Module: StaticDataModel::ClassMethods
- Defined in:
- lib/static_data_model.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#attribute_names ⇒ Object
readonly
Returns the value of attribute attribute_names.
Instance Method Summary collapse
-
#all ⇒ Object
Returns all instances of the model as listed in the model_data.
-
#find(id) ⇒ model class
Returns a specific model instance according to the given id.
-
#raises_activerecord_errors ⇒ Object
Call in class context to make the model raise errors as ActiveRecord models do.
Instance Attribute Details
#attribute_names ⇒ Object
Returns the value of attribute attribute_names.
68 69 70 |
# File 'lib/static_data_model.rb', line 68 def attribute_names @attribute_names end |
Instance Method Details
#all ⇒ Object
Returns all instances of the model as listed in the model_data
50 51 52 53 54 |
# File 'lib/static_data_model.rb', line 50 def all @all ||= model_data.map do |attrs| new(attrs) end end |
#find(id) ⇒ model class
Returns a specific model instance according to the given id
62 63 64 65 66 |
# File 'lib/static_data_model.rb', line 62 def find(id) all.find { |instance| instance.id == id } || raise(error_namespace::RecordNotFound, "Couldn't find #{self} with 'id'=#{id}") end |
#raises_activerecord_errors ⇒ Object
Call in class context to make the model raise errors as ActiveRecord models do. Make sure to have required active_record elsewhere already.
45 46 47 |
# File 'lib/static_data_model.rb', line 45 def raises_activerecord_errors @error_namespace = ::ActiveRecord end |