diff --git a/lib/the_moderator/model.rb b/lib/the_moderator/model.rb index 126db0f..4a3393f 100644 --- a/lib/the_moderator/model.rb +++ b/lib/the_moderator/model.rb @@ -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) diff --git a/lib/the_moderator/moderation_model.rb b/lib/the_moderator/moderation_model.rb index 16c047b..3288869 100644 --- a/lib/the_moderator/moderation_model.rb +++ b/lib/the_moderator/moderation_model.rb @@ -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