Add moderated? method to check if an attribute is being moderated

master
Guillaume DOTT 2013-11-27 10:01:09 +01:00
parent fc72e412bc
commit 76ba4d22de
2 changed files with 31 additions and 0 deletions

View File

@ -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)

View File

@ -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