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
164 165 166 167 168 169 170 171 172 |
# File 'lib/motion-loco/observable.rb', line 164 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
177 178 179 180 181 182 183 184 185 |
# File 'lib/motion-loco/observable.rb', line 177 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
187 188 189 190 191 192 193 194 195 |
# File 'lib/motion-loco/observable.rb', line 187 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
157 158 159 160 |
# File 'lib/motion-loco/observable.rb', line 157 def observer(name, proc) @class_bindings = get_class_bindings @class_bindings << { proc: proc } end |
#property(name, type = nil) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/motion-loco/observable.rb', line 140 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 |