Class: AttributeChanger::AttributeChange
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AttributeChanger::AttributeChange
- Defined in:
- lib/attribute_changer/attribute_change.rb
Class Method Summary collapse
Instance Method Summary collapse
- #dependent_attribs(o = obj) ⇒ Object
- #obj ⇒ Object
- #obj=(val) ⇒ Object
- #obj_type ⇒ Object
- #value ⇒ Object
- #value=(val) ⇒ Object
Class Method Details
.from_obj(obj) ⇒ Object
15 |
# File 'lib/attribute_changer/attribute_change.rb', line 15 def from_obj(obj); where("obj_type = ? AND obj_id = ?", obj.class.name, obj.id) end |
.pending ⇒ Object
16 |
# File 'lib/attribute_changer/attribute_change.rb', line 16 def pending; where("status = ?", 'pending') end |
.waiting ⇒ Object
17 |
# File 'lib/attribute_changer/attribute_change.rb', line 17 def waiting; where("status = ?", 'waiting') end |
Instance Method Details
#dependent_attribs(o = obj) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/attribute_changer/attribute_change.rb', line 45 def dependent_attribs(o = obj) attrib_was = o.send "#{attrib}" o.send "#{attrib}=", value o.valid? da = o.errors..map{|attr, errors| attr if errors.any?}.compact o.send "#{attrib}=", attrib_was o.valid? da end |
#obj ⇒ Object
26 27 28 29 30 |
# File 'lib/attribute_changer/attribute_change.rb', line 26 def obj if obj_type && obj_id @obj ||= obj_type.find_by_id obj_id end end |
#obj=(val) ⇒ Object
32 33 34 35 |
# File 'lib/attribute_changer/attribute_change.rb', line 32 def obj=(val) self.obj_id = val.id self.obj_type = val.class.to_s end |
#obj_type ⇒ Object
20 21 22 23 24 |
# File 'lib/attribute_changer/attribute_change.rb', line 20 def obj_type if val = read_attribute(:obj_type) val.constantize end end |
#value ⇒ Object
41 42 43 |
# File 'lib/attribute_changer/attribute_change.rb', line 41 def value deserialize end |
#value=(val) ⇒ Object
37 38 39 |
# File 'lib/attribute_changer/attribute_change.rb', line 37 def value=(val) write_attribute :value, serialize(val) end |