Module: Mitake::Model::Attributes Private

Defined in:
lib/mitake/model/attributes.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attributes = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Assign attribute by hash

Parameters:

  • attributes (Hash) (defaults to: {})

    the attributes to assignment

Since:

  • 0.1.0



19
20
21
22
23
24
25
26
27
# File 'lib/mitake/model/attributes.rb', line 19

def assign_attributes(attributes = {})
  attributes.each do |key, value|
    next unless self.class.attribute_names.include?(key.to_s)
    next send("#{key}=", value) if respond_to?("#{key}=")

    type = self.class.attributes[key.to_s]
    instance_variable_set("@#{key}", self.class.cast(value, type))
  end
end

#initialize(attributes = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



10
11
12
# File 'lib/mitake/model/attributes.rb', line 10

def initialize(attributes = {})
  assign_attributes(attributes)
end