Module: ZerigoDNS::Resource::Attributes::InstanceMethods

Defined in:
lib/zerigodns/resource/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(mtd, *args) ⇒ Object

Allows method-style access to the attributes.



10
11
12
13
14
15
16
17
18
# File 'lib/zerigodns/resource/attributes.rb', line 10

def method_missing mtd, *args
  if mtd.to_s.chars.to_a.last == '='
    raise ArgumentError, "Invalid number of arguments (#{args.length} for 1)" if args.length != 1
    attributes[mtd.to_s.slice(0,mtd.to_s.length-1)] = args.first
  else
    raise ArgumentError, "Invalid number of arguments (#{args.length} for 0)" if args.length != 0
    attributes[mtd.to_s]
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



6
7
8
# File 'lib/zerigodns/resource/attributes.rb', line 6

def attributes
  @attributes
end

Instance Method Details

#initialize(attributes = {}) ⇒ Object

Initialize a new resource

Parameters:

  • attributes (Hash) (defaults to: {})

    Initial attributes.



28
29
30
31
# File 'lib/zerigodns/resource/attributes.rb', line 28

def initialize attributes={}
  @attributes = {}
  merge_attributes attributes
end

#to_hashHash

Converts the resource to a hash

Returns:

  • (Hash)

    The attributes



22
23
24
# File 'lib/zerigodns/resource/attributes.rb', line 22

def to_hash
  attributes
end