Module: ModelHelpers
- Included in:
- ArrayModel, Model
- Defined in:
- lib/volt/models/model_helpers.rb
Overview
A place for things shared between an ArrayModel and a Model
Instance Method Summary collapse
-
#class_at_path(path) ⇒ Object
Gets the class for a model at the specified path.
- #deep_unwrap(value) ⇒ Object
-
#event_added(event, scope_provider, first) ⇒ Object
Pass to the persisotr.
-
#event_removed(event, no_more_events) ⇒ Object
Pass to the persistor.
Instance Method Details
#class_at_path(path) ⇒ Object
Gets the class for a model at the specified path.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/volt/models/model_helpers.rb', line 25 def class_at_path(path) if path && path.last == :[] begin # TODO: SECURITY on the back-end we need to check that the model class we're loading # is coming from the models folder. # remove the _ and then singularize klass_name = path[-2][1..-1].singularize.camelize klass_name = klass_name.camelize klass = Object.send(:const_get, klass_name.to_sym) rescue NameError => e # Ignore exception, just means the model isn't defined klass = Model end else klass = Model end return klass end |
#deep_unwrap(value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/volt/models/model_helpers.rb', line 4 def deep_unwrap(value) if value.is_a?(Model) value = value.to_h elsif value.is_a?(ArrayModel) value = value.to_a end return value end |
#event_added(event, scope_provider, first) ⇒ Object
Pass to the persisotr
15 16 17 |
# File 'lib/volt/models/model_helpers.rb', line 15 def event_added(event, scope_provider, first) @persistor.event_added(event, scope_provider, first) if @persistor end |
#event_removed(event, no_more_events) ⇒ Object
Pass to the persistor
20 21 22 |
# File 'lib/volt/models/model_helpers.rb', line 20 def event_removed(event, no_more_events) @persistor.event_removed(event, no_more_events) if @persistor end |