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

#attributesObject (readonly)

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

Checks for equality.

Examples:

Compare two objects

object == other

Parameters:

  • The (Object)

    other object to compare with

Returns:

  • (true, false)

    True if objects’ attributes are the same, false otherwise.



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