Module: Glamazon::Attributes

Included in:
Base
Defined in:
lib/glamazon/attributes.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &blk) ⇒ Object



4
5
6
7
# File 'lib/glamazon/attributes.rb', line 4

def method_missing(meth, *args, &blk)
  add_attribute(meth)
  meth.to_s =~ /\=$/ ? send(meth, args.first) : send(meth)
end

Instance Method Details

#[](attribute) ⇒ Object



17
18
19
# File 'lib/glamazon/attributes.rb', line 17

def [](attribute)
  attributes[attribute]
end

#[]=(attribute, value) ⇒ Object



21
22
23
# File 'lib/glamazon/attributes.rb', line 21

def []=(attribute, value)
  attributes[attribute] = value
end

#attributesObject



13
14
15
# File 'lib/glamazon/attributes.rb', line 13

def attributes
  @attributes ||= HashWithIndifferentAccess.new
end

#read_attribute(attribute) ⇒ Object



25
26
27
# File 'lib/glamazon/attributes.rb', line 25

def read_attribute(attribute)
  attributes[attribute]
end

#to_sObject



9
10
11
# File 'lib/glamazon/attributes.rb', line 9

def to_s
  attributes.inspect
end

#write_attribute(attribute, value) ⇒ Object



29
30
31
# File 'lib/glamazon/attributes.rb', line 29

def write_attribute(attribute, value)
  attributes[attribute] = value
end