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
172 173 174 175 176 177 178 179 180 |
# File 'lib/motion-loco/observable.rb', line 172 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
185 186 187 188 189 190 191 192 193 |
# File 'lib/motion-loco/observable.rb', line 185 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
195 196 197 198 199 200 201 202 203 |
# File 'lib/motion-loco/observable.rb', line 195 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
165 166 167 168 |
# File 'lib/motion-loco/observable.rb', line 165 def observer(name, proc) @class_bindings = get_class_bindings @class_bindings << { proc: proc } end |
#property(name, type = nil) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/motion-loco/observable.rb', line 148 def property(name, type=nil) name = name.to_sym @class_properties = get_class_properties unless @class_properties.include? name attr_accessor 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 |