Module: Toy::Attributes

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::AttributeMethods
Included in:
Dirty, Object, Timestamps
Defined in:
lib/toy/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



58
59
60
# File 'lib/toy/attributes.rb', line 58

def [](key)
  read_attribute(key)
end

#[]=(key, value) ⇒ Object



62
63
64
# File 'lib/toy/attributes.rb', line 62

def []=(key, value)
  write_attribute(key, value)
end

#attributesObject



43
44
45
# File 'lib/toy/attributes.rb', line 43

def attributes
  @attributes
end

#attributes=(attrs) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/toy/attributes.rb', line 47

def attributes=(attrs, *)
  return if attrs.nil?
  attrs.each do |key, value|
    if respond_to?("#{key}=")
      send("#{key}=", value)
    elsif attribute_method?(key)
      write_attribute(key, value)
    end
  end
end

#initialize(attrs = {}) ⇒ Object



38
39
40
41
# File 'lib/toy/attributes.rb', line 38

def initialize(attrs={})
  initialize_attributes
  self.attributes = attrs
end