lib/motion_bindable/bindable.rb in motion_bindable-0.0.6 vs lib/motion_bindable/bindable.rb in motion_bindable-0.1.0
- old
+ new
@@ -13,11 +13,13 @@
#
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))
+ case v
+ when Hash then bind_attributes(v, object.send(k))
+ when Array then v.each { |v| bind strategy_for(v).new(object, k).bind(v) }
else bind strategy_for(v).new(object, k).bind(v)
end
end
end
@@ -25,26 +27,21 @@
@bindings ||= []
@bindings << strategy
self
end
+ def unbind_all
+ @bindings.each { |b| b.unbind }
+ @bindings = []
+ end
+
def refresh
@bindings.each { |b| b.refresh }
self
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