Class: RailsBestPractices::Core::ModelAttributes

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_best_practices/core/model_attributes.rb

Overview

Model attributes container.

Instance Method Summary collapse

Constructor Details

#initializeModelAttributes



6
7
8
# File 'lib/rails_best_practices/core/model_attributes.rb', line 6

def initialize
  @attributes = {}
end

Instance Method Details

#add_attribute(model_name, attribute_name, attribute_type) ⇒ Object

Add a model attribute.



15
16
17
18
# File 'lib/rails_best_practices/core/model_attributes.rb', line 15

def add_attribute(model_name, attribute_name, attribute_type)
  @attributes[model_name] ||= {}
  @attributes[model_name][attribute_name] = attribute_type
end

#get_attribute_type(model_name, attribute_name) ⇒ String

Get attribute type.



25
26
27
28
# File 'lib/rails_best_practices/core/model_attributes.rb', line 25

def get_attribute_type(model_name, attribute_name)
  @attributes[model_name] ||= {}
  @attributes[model_name][attribute_name]
end

#is_attribute?(model_name, attribute_name) ⇒ Boolean

If it is a model’s attribute.



35
36
37
38
# File 'lib/rails_best_practices/core/model_attributes.rb', line 35

def is_attribute?(model_name, attribute_name)
  @attributes[model_name] ||= {}
  !!@attributes[model_name][attribute_name]
end