Module: RuGUI::ObservablePropertySupport::ClassMethods
- Defined in:
- lib/rugui/observable_property_support.rb
Instance Method Summary collapse
-
#core_observable_properties ⇒ Object
Returns the names of core observable properties for this class.
-
#create_class_inheritable_attributes ⇒ Object
Creates the necessary class inheritable attributes an initializes them.
-
#observable_properties ⇒ Object
Returns the names of all observable properties for this class.
-
#observable_property(property, options = {}) ⇒ Object
Register a observable properties for this model.
Instance Method Details
#core_observable_properties ⇒ Object
Returns the names of core observable properties for this class.
163 164 165 166 167 168 169 |
# File 'lib/rugui/observable_property_support.rb', line 163 def core_observable_properties core_observable_properties = [] .each do |property, | core_observable_properties << property if [:core] == true end core_observable_properties end |
#create_class_inheritable_attributes ⇒ Object
Creates the necessary class inheritable attributes an initializes them.
118 119 120 121 122 |
# File 'lib/rugui/observable_property_support.rb', line 118 def create_class_inheritable_attributes self.class_inheritable_accessor :observable_properties_options self. = {} end |
#observable_properties ⇒ Object
Returns the names of all observable properties for this class.
172 173 174 |
# File 'lib/rugui/observable_property_support.rb', line 172 def observable_properties .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
initializemethod is called). Defaults tonil. - 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, theinitial_valuewill be used instead. - core: Defines whether the property should be used when comparing two
observables. Defaults to
false. - prevent_reset: If this is
truethe property will not be reseted. Defaults to false. - boolean: If this is
truea "question" method will be created for the property (i.e., for a property namedfooa method namedfoo?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
156 157 158 159 160 |
# File 'lib/rugui/observable_property_support.rb', line 156 def observable_property(property, = {}) (property, ) create_observable_property_accessors(property) create_observable_property_boolean_readers(property, ) end |