Class: TrackIt::Wrapper
- Inherits:
-
Object
- Object
- TrackIt::Wrapper
- Includes:
- ActiveModel::AttributeMethods
- Defined in:
- lib/trackit/wrapper.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #changed ⇒ Object
- #changed? ⇒ Boolean
-
#initialize(model) ⇒ Wrapper
constructor
A new instance of Wrapper.
- #set_all_changed ⇒ Object
- #set_all_unchanged ⇒ Object
- #set_changed(attr) ⇒ Object
- #set_unchanged(attr) ⇒ Object
Constructor Details
#initialize(model) ⇒ Wrapper
Returns a new instance of Wrapper.
8 9 10 |
# File 'lib/trackit/wrapper.rb', line 8 def initialize(model) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/trackit/wrapper.rb', line 6 def model @model end |
Instance Method Details
#changed ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/trackit/wrapper.rb', line 16 def changed changed = [] bits_num = tracked_attributes.size (bits_num-1).downto(0) do |i| changed << tracked_attributes[i] if model.tracked_attributes[i] == 1 end changed end |
#changed? ⇒ Boolean
12 13 14 |
# File 'lib/trackit/wrapper.rb', line 12 def changed? model.tracked_attributes != 0 end |
#set_all_changed ⇒ Object
37 38 39 |
# File 'lib/trackit/wrapper.rb', line 37 def set_all_changed @model.tracked_attributes |= (~0) end |
#set_all_unchanged ⇒ Object
33 34 35 |
# File 'lib/trackit/wrapper.rb', line 33 def set_all_unchanged @model.tracked_attributes = 0 end |
#set_changed(attr) ⇒ Object
25 26 27 |
# File 'lib/trackit/wrapper.rb', line 25 def set_changed(attr) @model.tracked_attributes |= 2 ** tracked_attributes.index(attr) end |
#set_unchanged(attr) ⇒ Object
29 30 31 |
# File 'lib/trackit/wrapper.rb', line 29 def set_unchanged(attr) @model.tracked_attributes &= ~(2 ** tracked_attributes.index(attr)) end |