Class: Unleashed::BaseResource

Inherits:
Object
  • Object
show all
Defined in:
lib/unleashed/resources/base_resource.rb

Overview

Base resource for all the other resources to inherit from

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ BaseResource

Returns a new instance of BaseResource.



4
5
6
# File 'lib/unleashed/resources/base_resource.rb', line 4

def initialize(client)
  @client = client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



8
9
10
11
12
13
14
# File 'lib/unleashed/resources/base_resource.rb', line 8

def method_missing(name, *args, &block)
  if instance_methods.include?(model) && respond_to?(name)
    model.new(@client, id: args[0]).send(name, *args[1..-1])
  else
    super
  end
end

Instance Method Details

#respond_to?(name, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/unleashed/resources/base_resource.rb', line 16

def respond_to?(name, include_all = false)
  super || model.new(@client).respond_to?(name, include_all)
end