Module: MotionBindable::Bindable
- Defined in:
- lib/motion_bindable/bindable.rb
Overview
Bindable Module
Allow attributes of an object to be bound to other arbitrary objects through unique strategies.
One-way binding
Currently bindings are only one-way, i.e change in the arbitrary object affects the bindable object but not vice-versa.
Instance Method Summary collapse
Instance Method Details
#bind(strategy) ⇒ Object
24 25 26 27 28 |
# File 'lib/motion_bindable/bindable.rb', line 24 def bind(strategy) @bindings ||= [] @bindings << strategy self end |
#bind_attributes(attrs, object = self) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/motion_bindable/bindable.rb', line 16 def bind_attributes(attrs, object = self) attrs.each_pair do |k, v| if v.is_a?(Hash) then bind_attributes(v, object.send(k)) else bind strategy_for(v).new(object, k).bind(v) end end end |
#refresh ⇒ Object
30 31 32 |
# File 'lib/motion_bindable/bindable.rb', line 30 def refresh @bindings.each { |b| b.refresh } end |