Module: RuGUI::ObservablePropertySupport::ClassMethods

Defined in:
lib/rugui/observable_property_support.rb

Instance Method Summary collapse

Instance Method Details

#core_observable_propertiesObject

Returns the names of core observable properties for this class.



166
167
168
169
170
171
172
# File 'lib/rugui/observable_property_support.rb', line 166

def core_observable_properties
  core_observable_properties = []
  observable_properties_options.each do |property, options|
    core_observable_properties << property if options[:core] == true
  end
  core_observable_properties
end

#create_class_inheritable_attributesObject

Creates the necessary class inheritable attributes an initializes them.



121
122
123
124
125
# File 'lib/rugui/observable_property_support.rb', line 121

def create_class_inheritable_attributes
  self.class_inheritable_accessor :observable_properties_options

  self.observable_properties_options = {}
end

#observable_propertiesObject

Returns the names of all observable properties for this class.



175
176
177
# File 'lib/rugui/observable_property_support.rb', line 175

def observable_properties
  observable_properties_options.keys
end

#observable_property(property, options = {}) ⇒ Object

Register a observable properties for this model.

Properties may be given as symbols, or strings. You can pass some options, in a hash, which will be used when the observable is created:

  • initial_value: The initial value for the property. This value will

be set when the observable instance is initialized (i.e., when the initialize method is called). Defaults to nil.

  • reset_value: The reset value for the property. This value will be

set when the observable instance is reset (i.e., when the reset! method is called). If this is not given, the initial_value will be used instead.

  • core: Defines whether the property should be used when comparing two

observables. Defaults to false.

  • prevent_reset: If this is true the property will not be

reseted. Defaults to false.

  • boolean: If this is true a “question” method will be

created for the property (i.e., for a property named foo a method named foo? will be created).

Examples:

class MyObservable
  include RuGUI::ObservablePropertySupport

  observable_property :foo, :initial_value => "bar"
  observable_property :bar, :initial_value => "foo", :reset_value => "bar"
  observable_property :core_property, :core => true
  observable_property :non_resetable_property, :prevent_reset => true

  # And so on...
end


159
160
161
162
163
# File 'lib/rugui/observable_property_support.rb', line 159

def observable_property(property, options = {})
  create_observable_property_options(property, options)
  create_observable_property_accessors(property)
  create_observable_property_boolean_readers(property, options)
end