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

Returns a new instance of ModelAttributes.



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

def initialize
  @attributes = {}
end

Instance Method Details

#add_attribute(model_name, attribute_name, attribute_type) ⇒ Object

Add a model attribute.

Parameters:

  • model (String)

    name

  • attribute (String)

    name

  • attribute (String)

    type



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

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.

Parameters:

  • model (String)

    name

  • attribute (String)

    name

Returns:

  • (String)

    attribute type



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

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.

Parameters:

  • model (String)

    name

  • attribute (String)

    name

Returns:

  • (Boolean)

    true if it is the model’s attribute



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

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