Module: HasModerated::Common::InstanceMethods
- Defined in:
- lib/has_moderated/common.rb
Instance Method Summary collapse
- #add_associations_moderated(assocs_data) ⇒ Object
- #create_moderation_with_hooks!(*args) ⇒ Object
-
#delete_associations_moderated(assocs) ⇒ Object
moderate removing associations.
- #get_moderation_attributes ⇒ Object
- #without_moderation(do_disable = true) ⇒ Object
Instance Method Details
#add_associations_moderated(assocs_data) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/has_moderated/common.rb', line 68 def add_associations_moderated assocs_data # convert associations data so it can be serialized assocs_processed = Hash.new assocs_data.each_pair do |assoc_name, assoc_data_array| assocs_processed[assoc_name] = [] assoc_data_array.each do |assoc_data| # convert assoc data to either ID or, if it's a new record, hash of its attributes pdata = HasModerated::ActiveRecordHelpers::hashize_association(self, assoc_name, assoc_data) assocs_processed[assoc_name].push(pdata) end end # create moderation for adding the associations and return it moderations = [] unless assocs_processed.empty? moderations.push(create_moderation_with_hooks!( :associations => assocs_processed )) end moderations end |
#create_moderation_with_hooks!(*args) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/has_moderated/common.rb', line 52 def create_moderation_with_hooks!(*args) is_create = args.first[:create].present? if is_create m = Moderation.new m.moderatable_type = self.class.to_s else m = self.moderations.build end m.data = args.first HasModerated::Common::call_creating_hook(self, m) # if self is a new_record? then let AR create the moderations # when self is saved m.save! if is_create || !self.new_record? m end |
#delete_associations_moderated(assocs) ⇒ Object
moderate removing associations
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/has_moderated/common.rb', line 92 def delete_associations_moderated(assocs) moderations = [] unless assocs.empty? moderations.push(create_moderation_with_hooks!( :delete_associations => assocs )) end moderations end |
#get_moderation_attributes ⇒ Object
48 49 50 |
# File 'lib/has_moderated/common.rb', line 48 def get_moderation_attributes HasModerated::ActiveRecordHelpers::get_default_moderation_attributes(self) end |
#without_moderation(do_disable = true) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/has_moderated/common.rb', line 37 def without_moderation(do_disable = true) already_disabled = @moderation_disabled self.moderation_disabled = true if do_disable begin retval = yield(self) ensure self.moderation_disabled = false if do_disable && !already_disabled end retval end |