Class: Round::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/round/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource:, client:, **kwargs) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/round/base.rb', line 5

def initialize(resource:, client:, **kwargs)
  @resource = resource
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



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

def method_missing(meth, *args, &block)
  @resource.send(meth, *args, &block)
rescue => e
  @resource.attributes.fetch(meth) do
    raise e
  end
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



3
4
5
# File 'lib/round/base.rb', line 3

def resource
  @resource
end

Class Method Details

.association(name, klass) ⇒ Object



31
32
33
34
35
# File 'lib/round/base.rb', line 31

def self.association(name, klass)
  define_method(name) do
    Kernel.const_get(klass).new(resource: @resource.send(name), client: @client).refresh
  end
end

.hash_identifierObject



27
28
29
# File 'lib/round/base.rb', line 27

def self.hash_identifier
  "key"
end

Instance Method Details

#hash_identifierObject



23
24
25
# File 'lib/round/base.rb', line 23

def hash_identifier
  send :[], self.class.hash_identifier
end

#refreshObject



10
11
12
13
# File 'lib/round/base.rb', line 10

def refresh
  @resource = @resource.get
  self
end