Module: StaticDataModel::ClassMethods

Defined in:
lib/static_data_model.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attribute_namesObject

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

#allObject

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

Raises:

  • (ActiveRecord::RecordNotFound)

    if no attachment context type was found for 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_errorsObject

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