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.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FrameworkAdapters::FrameworkAdapterSupport

#framework_adapter_for, #load_framework_adapter

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.send(:include, RuGUI::PropertyChangedSupport)
end

Instance Method Details

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



48
49
50
# File 'lib/rugui/property_observer.rb', line 48

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



40
41
42
43
44
45
46
# File 'lib/rugui/property_observer.rb', line 40

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)
  self.property_changed_blocks.each do |property_changed_block|
    property_changed_block.call_property_changed_block_if_exists(self, observable, property, new_value, old_value)
  end
end