Module: ActiveRecord::Acts::Applyable::InstanceMethods
- Defined in:
- lib/acts_as_applyable.rb
Instance Method Summary collapse
- #apply(*attributes) ⇒ Object
- #apply!(*attributes) ⇒ Object
-
#apply_all ⇒ Object
alias for save.
-
#apply_all! ⇒ Object
alias for save!.
- #apply_set_attributes(*attribute_list) ⇒ Object
- #params ⇒ Object
- #params=(new_params) ⇒ Object
Instance Method Details
#apply(*attributes) ⇒ Object
43 44 45 46 |
# File 'lib/acts_as_applyable.rb', line 43 def apply(*attributes) apply_set_attributes(*attributes) save end |
#apply!(*attributes) ⇒ Object
48 49 50 51 |
# File 'lib/acts_as_applyable.rb', line 48 def apply!(*attributes) apply_set_attributes(*attributes) save! end |
#apply_all ⇒ Object
alias for save
54 55 56 57 |
# File 'lib/acts_as_applyable.rb', line 54 def apply_all self.attributes = params save end |
#apply_all! ⇒ Object
alias for save!
60 61 62 63 |
# File 'lib/acts_as_applyable.rb', line 60 def apply_all! self.attributes = params save! end |
#apply_set_attributes(*attribute_list) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/acts_as_applyable.rb', line 20 def apply_set_attributes(*attribute_list) self.params.stringify_keys! # initialize attribute list if empty if attribute_list.empty? if self.respond_to?(:applyable_fields) attribute_list = self.applyable_fields else Rails.logger.error("\n\n-------\n\nNO APPLYABLE FIELDS FOUND FOR #{self.class.to_s}\n"+ "Define a method called applyable_fields and return the array fields to apply by default\n\n-------\n\n") end end # build attributes hash attributes = {} attribute_list.each do |attribute| attributes[attribute] = self.params[attribute.to_s] end # set attributes, ignoring protected send :attributes=, attributes, false end |
#params ⇒ Object
11 12 13 14 |
# File 'lib/acts_as_applyable.rb', line 11 def params @params ||= {} @params end |
#params=(new_params) ⇒ Object
16 17 18 |
# File 'lib/acts_as_applyable.rb', line 16 def params=(new_params) @params = new_params end |