Class: Marathon::Base

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/marathon/base.rb

Overview

Base class for all the API specific classes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Error

error_class, error_message, from_response

Constructor Details

#initialize(hash, attr_accessors = []) ⇒ Base

Create the object hash: object returned from API. May be Hash or Array. attr_accessors: List of attribute accessors.

Raises:



11
12
13
14
15
16
17
# File 'lib/marathon/base.rb', line 11

def initialize(hash, attr_accessors = [])
  raise ArgumentError, 'hash must be a Hash' if attr_accessors and attr_accessors.size > 0 and not hash.is_a?(Hash)
  raise ArgumentError, 'hash must be Hash or Array' unless hash.is_a?(Hash) or hash.is_a?(Array)
  raise ArgumentError, 'attr_accessors must be an Array' unless attr_accessors.is_a?(Array)
  @info = Marathon::Util.keywordize_hash!(hash)
  attr_accessors.each { |e| add_attr_accessor(e) }
end

Instance Attribute Details

#infoObject (readonly)

Returns the value of attribute info.



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

def info
  @info
end

Instance Method Details

#to_json(opts = {}) ⇒ Object

Return application as JSON formatted string.



20
21
22
# File 'lib/marathon/base.rb', line 20

def to_json(opts = {})
  info.to_json(opts)
end