Sha256: 7ac959c611075f3c29d4f5eed8f05ada89b3b712ca3d39115f86b70d7177c134
Contents?: true
Size: 1017 Bytes
Versions: 1
Compression:
Stored size: 1017 Bytes
Contents
module MotionBindable # # # 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. # module Bindable 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 def bind(strategy) @bindings ||= [] @bindings << strategy self end def refresh @bindings.each { |b| b.refresh } end private def strategy_for(reference) Strategy.find_by_reference(reference) end def underscore(str) str.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') .gsub(/([a-z\d])([A-Z])/,'\1_\2') .tr("-", "_") .downcase end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
motion_bindable-0.0.1 | lib/motion_bindable/bindable.rb |