module StaticDataModel::ClassMethods
Attributes
attribute_names[R]
model_data[R]
Public Instance Methods
all()
click to toggle source
Returns all instances of the model as listed in the model_data
# File lib/static_data_model.rb, line 50 def all @all ||= model_data.map do |attrs| new(attrs) end end
find(id)
click to toggle source
Returns a specific model instance according to the given id
@param [String] id the identifier of the instance @raise [ActiveRecord::RecordNotFound] if no attachment context type
was found for the given id
@return [model class] the instance for the given id
# 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()
click to toggle source
Call in class context to make the model raise errors as ActiveRecord models do. Make sure to have required active_record elsewhere already.
# File lib/static_data_model.rb, line 45 def raises_activerecord_errors @error_namespace = ::ActiveRecord end
Private Instance Methods
attribute_names=(ary)
click to toggle source
# File lib/static_data_model.rb, line 79 def attribute_names=(ary) @attribute_names = ary attr_reader(*@attribute_names) end
error_namespace()
click to toggle source
# File lib/static_data_model.rb, line 84 def error_namespace @error_namespace || Errors end
model_data=(ary)
click to toggle source
# File lib/static_data_model.rb, line 74 def model_data=(ary) @model_data = ary self.attribute_names = ary.map(&:keys).flatten.uniq end