Class: Ecfr::Base

Inherits:
Client show all
Extended by:
Extensible
Includes:
AttributeMethodDefinition, Enumerable
Defined in:
lib/ecfr/base.rb

Defined Under Namespace

Classes: Metadata

Constant Summary collapse

SUPPORTED_ARRAY_ACCESSORS =
i[empty? first last size]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Extensible

inherited

Methods included from AttributeMethodDefinition

included

Methods inherited from Client

build, cache_key, client, client_pool, delete, execute, get, handle_response, perform, post, purge

Methods included from ParallelClient

included

Constructor Details

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

Returns a new instance of Base.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ecfr/base.rb', line 38

def initialize(attributes = {}, options = {})
  default_options = {base: true}
  options = default_options.merge(options)

  @response_status = options.delete(:response_status)
  @request_data = options.delete(:request_data)

  # - handle result_root only if the first time instantiating
  #     the class from the results
  # - some responses won't be a parsed attribute hash
  if options[:base] && attributes.is_a?(Hash)
     = .new(attributes.delete(self.class.))

    if result_root && attributes[result_root]
      @results = attributes[result_root].map do |r|
        self.class.new(r, base: false)
      end
    end
  end

  super(attributes)
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



32
33
34
# File 'lib/ecfr/base.rb', line 32

def 
  
end

#request_dataObject (readonly)

Returns the value of attribute request_data.



32
33
34
# File 'lib/ecfr/base.rb', line 32

def request_data
  @request_data
end

#response_statusObject (readonly)

Returns the value of attribute response_status.



32
33
34
# File 'lib/ecfr/base.rb', line 32

def response_status
  @response_status
end

#resultsObject (readonly) Also known as: all

Returns the value of attribute results.



32
33
34
# File 'lib/ecfr/base.rb', line 32

def results
  @results
end

Class Method Details

.basic_auth_client_optionsObject



19
20
21
22
23
24
25
26
# File 'lib/ecfr/base.rb', line 19

def self.basic_auth_client_options
  {
    basic_auth: {
      username: Ecfr.config.ecfr_basic_auth_username,
      password: Ecfr.config.ecfr_basic_auth_password
    }
  }
end

.metadata(*metadata) ⇒ Object



28
29
30
# File 'lib/ecfr/base.rb', line 28

def self.(*)
  .attribute(*)
end

.metadata_key(key) ⇒ Object



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

def self.(key)
  self. = key.to_s
end

.result_key(key) ⇒ Object



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

def self.result_key(key)
  self.result_root = key.to_s
end

Instance Method Details

#eachObject



61
62
63
# File 'lib/ecfr/base.rb', line 61

def each
  @results.each { |result| yield result }
end