Module: RuGUI::PropertyObserver

Includes:
FrameworkAdapters::FrameworkAdapterSupport
Included in:
BaseController, BaseView
Defined in:
lib/rugui/property_observer.rb

Overview

Adds observer functionality for any class which has support for observable properties.

The observer class should implement a method name ‘property_property_name_changed’, where ‘property_name’ is the name of the observable property, that will be called whenever that property value has changed. If it does not declare a method with this name, it will be silently ignored.

The method signature is:

property_foo_changed(model, new_value, old_value)

for a property named ‘foo’.

If the observer class declares a method with this signature:

property_my_class_foo_changed(model, new_value, old_value)

it will be called whenever the property foo of an observable of the class MyClass has changed.

Also, if the observer class declares a method with this signature:

property_my_named_observable_foo_changed(model, new_value, old_value)

it will be called whenever the property foo of the observable named my_named_observable has changed. To declare named observers, you must register the observer passing a name to the ObservablePropertySupport#register_observer method.

Instance Method Summary collapse

Methods included from FrameworkAdapters::FrameworkAdapterSupport

#framework_adapter_for, included, #load_framework_adapter

Instance Method Details

#named_observable_property_updated(observable_name, observable, property, new_value, old_value) ⇒ Object



41
42
43
# File 'lib/rugui/property_observer.rb', line 41

def named_observable_property_updated(observable_name, observable, property, new_value, old_value)
  queue_method_call_if_exists("property_#{observable_name}_#{property}_changed", observable, new_value, old_value) unless named_observable_collides_with_class_name?(observable_name, observable)
end

#property_updated(observable, property, new_value, old_value) ⇒ Object



36
37
38
39
# File 'lib/rugui/property_observer.rb', line 36

def property_updated(observable, property, new_value, old_value)
  queue_method_call_if_exists("property_#{property}_changed", observable, new_value, old_value)
  queue_method_call_if_exists("property_#{observable.class.name.underscore}_#{property}_changed", observable, new_value, old_value)
end