Class: Kentaa::Api::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/kentaa/api/resources/base.rb

Direct Known Subclasses

List, Resource, Sites

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
# File 'lib/kentaa/api/resources/base.rb', line 9

def initialize(config, options = {})
  @config = config
  @options = options
  @resource_class = options.delete(:resource_class) || self.class
  @endpoint_path = options.delete(:endpoint_path)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/kentaa/api/resources/base.rb', line 7

def config
  @config
end

#endpoint_pathObject (readonly)

Returns the value of attribute endpoint_path.



7
8
9
# File 'lib/kentaa/api/resources/base.rb', line 7

def endpoint_path
  @endpoint_path
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/kentaa/api/resources/base.rb', line 7

def options
  @options
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



7
8
9
# File 'lib/kentaa/api/resources/base.rb', line 7

def resource_class
  @resource_class
end

Class Method Details

.attribute_keyObject



17
18
19
20
# File 'lib/kentaa/api/resources/base.rb', line 17

def attribute_key
  class_name = name.split('::').last
  class_name.gsub(/([^\^])([A-Z])/, '\1_\2').downcase
end

Instance Method Details

#loadObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/kentaa/api/resources/base.rb', line 23

def load
  @response ||=
    if block_given?
      yield
    else
      load_resource
    end

  self
end

#loaded?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/kentaa/api/resources/base.rb', line 34

def loaded?
  !@response.nil?
end