Module: Tyrion::Attributes::InstanceMethods
- Defined in:
- lib/tyrion/attributes.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/tyrion/attributes.rb', line 24
def method_missing(name, *args)
attr = name.to_s
return super unless attributes.has_key? attr.gsub("=", "")
if attr =~ /=$/
write_attribute(attr[0..-2], args.shift || raise("BOOM"))
else
read_attribute(attr)
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
18
19
20
|
# File 'lib/tyrion/attributes.rb', line 18
def attributes
@attributes
end
|
Instance Method Details
#==(other) ⇒ true, false
40
41
42
43
|
# File 'lib/tyrion/attributes.rb', line 40
def == other
return false unless other.is_a?(Tyrion::Document)
other.attributes == attributes
end
|
#initialize(attrs = {}) ⇒ Object
20
21
22
|
# File 'lib/tyrion/attributes.rb', line 20
def initialize(attrs = {})
@attributes = attrs.stringify_keys
end
|
#read_attribute(name) ⇒ Object
45
46
47
|
# File 'lib/tyrion/attributes.rb', line 45
def read_attribute(name)
attributes[name.to_s]
end
|
#write_attribute(name, arg) ⇒ Object
49
50
51
|
# File 'lib/tyrion/attributes.rb', line 49
def write_attribute(name, arg)
attributes[name.to_s] = arg
end
|