Class: Zoid::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/zoid/resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Resource

Returns a new instance of Resource.



3
4
5
# File 'lib/zoid/resource.rb', line 3

def initialize(hash)
  @attributes = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/zoid/resource.rb', line 15

def method_missing(method, *args)
  if @attributes.has_key?(method.to_s)
    @attributes[method.to_s]
  else
    super
  end
end

Instance Method Details

#has?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/zoid/resource.rb', line 7

def has?(attribute)
  @attributes.has_key?(attribute.to_s)
end

#inspectObject



27
28
29
# File 'lib/zoid/resource.rb', line 27

def inspect
  "<#{self.class.name}:#{object_id} #{@attributes.keys}>"
end

#methodsObject



23
24
25
# File 'lib/zoid/resource.rb', line 23

def methods
  super + @attributes.keys.map(&:to_sym)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/zoid/resource.rb', line 11

def respond_to_missing?(method, include_private = false)
  @attributes.has_key?[method.to_s]
end