Module: TheModerator::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/the_moderator/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#moderate(*moderated_attributes) ⇒ Object



14
15
16
17
18
# File 'lib/the_moderator/model.rb', line 14

def moderate(*moderated_attributes)
  data = moderation_data(*moderated_attributes)
  moderations.build(data: {attributes: data[:data]},
                    data_display: data[:data_display]) unless data[:data].empty?
end

#moderated?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/the_moderator/model.rb', line 20

def moderated?(attr_name)
  moderations.each do |moderation|
    return true if moderation.include?(attr_name)
  end
  false
end

#moderated_fields_for(assoc) ⇒ Object



27
28
29
30
# File 'lib/the_moderator/model.rb', line 27

def moderated_fields_for(assoc)
  moderations.map { |m| m.moderated_fields_for(assoc) }
             .inject(&:|)
end