Module: ActiveRemote::Attributes

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

Instance Method Summary collapse

Instance Method Details

#attributesObject



3
4
5
6
7
8
9
# File 'lib/active_remote/attributes.rb', line 3

def attributes
  @attributes ||= begin
    attribute_names = self.class.attribute_names
    Hash[attribute_names.map { |key| [key, send(key)] }]
  end
  @attributes.dup
end

#read_attribute(name) ⇒ Object Also known as: []

Read attribute from the attributes hash



13
14
15
16
17
18
19
20
21
# File 'lib/active_remote/attributes.rb', line 13

def read_attribute(name)
  name = name.to_s

  if respond_to? name
    attribute(name)
  else
    raise ActiveAttr::UnknownAttributeError, "unknown attribute: #{name}"
  end
end

#write_attribute(name, value) ⇒ Object Also known as: []=

Update an attribute in the attributes hash



26
27
28
29
30
31
32
33
34
# File 'lib/active_remote/attributes.rb', line 26

def write_attribute(name, value)
  name = name.to_s

  if respond_to? "#{name}="
    __send__("attribute=", name, value)
  else
    raise ActiveAttr::UnknownAttributeError, "unknown attribute: #{name}"
  end
end