Add moderated? method to check if an attribute is being moderated
parent
fc72e412bc
commit
76ba4d22de
|
@ -9,6 +9,13 @@ module TheModerator
|
|||
moderations.build(data: {attributes: data}) unless data.empty?
|
||||
end
|
||||
|
||||
def moderated?(attr_name)
|
||||
moderations.each do |moderation|
|
||||
return true if moderation.include?(attr_name)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def moderation_data(*moderated_attributes)
|
||||
|
|
|
@ -32,5 +32,29 @@ module TheModerator
|
|||
preview.attributes = data
|
||||
preview.freeze
|
||||
end
|
||||
|
||||
def parsed_data
|
||||
data
|
||||
end
|
||||
|
||||
def include?(attribute)
|
||||
include_attribute?(attribute, data[:attributes])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def include_attribute?(attribute, attr_data)
|
||||
return false if attr_data.nil?
|
||||
if attribute.is_a?(Hash)
|
||||
include_assoc?(attribute, attr_data)
|
||||
else
|
||||
attr_data.keys.include?(attribute)
|
||||
end
|
||||
end
|
||||
|
||||
def include_assoc?(attribute, assoc_data)
|
||||
include_attribute?(attribute.first.last,
|
||||
assoc_data[attribute.first.first])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue