Class: ActiveTouch::Touch
- Inherits:
-
Object
- Object
- ActiveTouch::Touch
- Defined in:
- lib/active_touch/touch.rb
Instance Attribute Summary collapse
-
#after_touch ⇒ Object
Returns the value of attribute after_touch.
-
#association ⇒ Object
Returns the value of attribute association.
-
#is_destroy ⇒ Object
Returns the value of attribute is_destroy.
-
#is_touched ⇒ Object
Returns the value of attribute is_touched.
-
#record ⇒ Object
Returns the value of attribute record.
-
#touch_updates ⇒ Object
Returns the value of attribute touch_updates.
Instance Method Summary collapse
- #associated ⇒ Object
-
#initialize(record, association, options = {}) ⇒ Touch
constructor
A new instance of Touch.
- #run ⇒ Object
Constructor Details
#initialize(record, association, options = {}) ⇒ Touch
Returns a new instance of Touch.
6 7 8 9 10 11 12 13 |
# File 'lib/active_touch/touch.rb', line 6 def initialize(record, association, = {}) @record = record @association = association @after_touch = [:after_touch] @is_destroy = [:is_destroy] @is_touched = [:is_touched] @touch_updates = ([:touch_updates] || {}) end |
Instance Attribute Details
#after_touch ⇒ Object
Returns the value of attribute after_touch.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def after_touch @after_touch end |
#association ⇒ Object
Returns the value of attribute association.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def association @association end |
#is_destroy ⇒ Object
Returns the value of attribute is_destroy.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def is_destroy @is_destroy end |
#is_touched ⇒ Object
Returns the value of attribute is_touched.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def is_touched @is_touched end |
#record ⇒ Object
Returns the value of attribute record.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def record @record end |
#touch_updates ⇒ Object
Returns the value of attribute touch_updates.
4 5 6 |
# File 'lib/active_touch/touch.rb', line 4 def touch_updates @touch_updates end |
Instance Method Details
#associated ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/active_touch/touch.rb', line 28 def associated @associated ||= begin if association == 'self' is_destroy || record.destroyed? ? nil : record else record.send(association) end end end |
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_touch/touch.rb', line 15 def run touch_updates[ActiveTouch.configuration.] = record.updated_at if associated.is_a? ActiveRecord::Base associated.update_columns(touch_updates) if !ActiveTouch.configuration..nil? && !is_touched associated.send(after_touch) unless after_touch.blank? elsif !associated.nil? associated.update_all(touch_updates) if !ActiveTouch.configuration..nil? && !is_touched associated.each { |associate| associate.send(after_touch) } unless after_touch.blank? end end |