Module: Loco::Observable::ClassMethods
- Defined in:
- lib/motion-loco/observable.rb
Instance Method Summary collapse
-
#get_class_bindings ⇒ Array
An array of the model’s bindings.
-
#get_class_properties ⇒ Array
An array of the model’s properties used for saving the record.
- #get_class_relationships ⇒ Object
- #observer(name, proc) ⇒ Object
- #property(name, type = nil) ⇒ Object
Instance Method Details
#get_class_bindings ⇒ Array
An array of the model’s bindings
160 161 162 163 164 165 166 167 168 |
# File 'lib/motion-loco/observable.rb', line 160 def get_class_bindings if @class_bindings.nil? @class_bindings = [] if self.superclass.respond_to? :get_class_bindings @class_bindings.concat(self.superclass.get_class_bindings) end end @class_bindings end |
#get_class_properties ⇒ Array
An array of the model’s properties used for saving the record
173 174 175 176 177 178 179 180 181 |
# File 'lib/motion-loco/observable.rb', line 173 def get_class_properties if @class_properties.nil? @class_properties = [] if self.superclass.respond_to? :get_class_properties @class_properties.concat(self.superclass.get_class_properties) end end @class_properties end |
#get_class_relationships ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/motion-loco/observable.rb', line 183 def get_class_relationships if @class_relationships.nil? @class_relationships = [] if self.superclass.respond_to? :get_class_relationships @class_relationships.concat(self.superclass.get_class_relationships) end end @class_relationships end |
#observer(name, proc) ⇒ Object
153 154 155 156 |
# File 'lib/motion-loco/observable.rb', line 153 def observer(name, proc) @class_bindings = get_class_bindings @class_bindings << { proc: proc } end |
#property(name, type = nil) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/motion-loco/observable.rb', line 134 def property(name, type=nil) name = name.to_sym @class_properties = get_class_properties unless @class_properties.include? name attr_accessor name alias_method name.to_s.camelize(:lower), name alias_method "#{name.to_s.camelize(:lower)}=", "#{name}=" end if type.is_a? Proc @class_bindings = get_class_bindings @class_bindings << { name: name, proc: type } else type = type.to_sym unless type.nil? @class_properties << { name: name, type: type } end end |