module MotionBindable::Bindable

# Bindable Module

Allow attributes of an object to be bound to other arbitrary objects through unique strategies.

Public Instance Methods

bind(strategy) click to toggle source
# File lib/motion_bindable/bindable.rb, line 24
def bind(strategy)
  @bindings ||= []
  @bindings << strategy
  self
end
bind_attributes(attrs, object = self) click to toggle source
# File lib/motion_bindable/bindable.rb, line 11
def bind_attributes(attrs, object = self)
  attrs.each_pair do |k, v|
    case v
    # Recurse if another hash
    when Hash then bind_attributes(v, object.send(k))
    # Allow binding multiple bound if an array
    when Array then v.each { |v| bind strategy_for(v).new(object, k).bind(v) }
    # Otherwise bind
    else bind strategy_for(v).new(object, k).bind(v)
    end
  end
end
strategy_for(reference) click to toggle source
# File lib/motion_bindable/bindable.rb, line 36
def strategy_for(reference)
  Strategy.find_by_reference(reference)
end
unbind_all() click to toggle source
# File lib/motion_bindable/bindable.rb, line 30
def unbind_all
  @bindings ||= []
  @bindings.each { |b| b.unbind }
  @bindings = []
end