lib/motion_bindable/strategy.rb in motion_bindable-0.2.2 vs lib/motion_bindable/strategy.rb in motion_bindable-0.2.3
- old
+ new
@@ -16,10 +16,11 @@
end.fetch(:class)
end
attr_accessor :object
attr_accessor :bound
+ attr_reader :attr_name
def initialize(object, attr_name)
@attr_name = attr_name.to_sym
self.object = object
end
@@ -37,37 +38,33 @@
initial_state
start_listen
self
end
- def refresh_object
- attribute
- end
-
def unbind
@watching = nil
end
private # Methods to leave alone
def attribute
- object.send(@attr_name)
+ object.send(attr_name)
end
def attribute=(value)
- object.send(:"#{@attr_name.to_s}=", value)
+ object.send(:"#{attr_name.to_s}=", value)
end
def initial_state
- if attribute.nil?
+ if attribute.nil? && respond_to?(:on_bound_change)
if respond_to?(:refresh_bound) then on_bound_change(refresh_bound)
else on_bound_change
- end if respond_to?(:on_bound_change)
- else
+ end
+ elsif respond_to?(:on_object_change)
if respond_to?(:refresh_object) then on_object_change(refresh_object)
else on_object_change(attribute)
- end if respond_to?(:on_object_change)
+ end
end
end
def start_listen
sides = []
@@ -76,10 +73,10 @@
elsif respond_to?(:refresh_bound) && respond_to?(:on_bound_change)
sides << :bound
end
if respond_to?(:start_observing_object) then start_observing_object
elsif respond_to?(:refresh_object) && respond_to?(:on_object_change)
- sides << object
+ sides << :object
end
watch(sides)
end