Class: Camdram::Base

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/camdram/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, key = nil) ⇒ Object

Instantiate a new object from a JSON hash

Parameters:

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

    A single JSON hash with symbolized keys.

  • key (Object) (defaults to: nil)

    The Camdram::Client instance key for the API multiton.


15
16
17
18
# File 'lib/camdram/base.rb', line 15

def initialize(options = {}, key = nil)
  set_from_hash(options)
  @client_instance = key
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id


8
9
10
# File 'lib/camdram/base.rb', line 8

def id
  @id
end

Instance Method Details

#make_orphanObject

Removes the HTTP instance from any module contained within the Camdram module namespace. Also removes the HTTP instance from any sub-objects as well. This may be useful in some multi-threaded environments if you have a connection pool of Camdram::Client objects.

Returns:

  • (Object)

    The object on which the method is called.


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/camdram/base.rb', line 26

def make_orphan
  @client_instance = -1 if instance_variable_defined?(:@client_instance)
  instance_variables.each do |var|
    value = instance_variable_get(var)
    if value.class.name.split('::').first == 'Camdram'
      value.make_orphan
    elsif value.class.name.split('::').first == 'Array'
      value.each { |v| v.make_orphan }
    end
  end
  self
end