Class: HttpClientGenerator::ResourcesDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/http_client_generator/resources_definition.rb

Overview

:nodoc:

Constant Summary collapse

DEFAULT_OPTIONS =
{
  content_type: :json
}.freeze
HTTP_VERBS =
%i[get post put patch].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, req_plugs = [], response_plugs = {}, timeout = nil) ⇒ ResourcesDefinition

Returns a new instance of ResourcesDefinition.



13
14
15
16
17
18
19
20
# File 'lib/http_client_generator/resources_definition.rb', line 13

def initialize(base, req_plugs = [], response_plugs = {}, timeout = nil)
  @base = base
  @resources = []
  @req_plugs = req_plugs
  @resp_head_plugs = response_plugs.fetch(:head, [])
  @resp_plugs = response_plugs.fetch(:body, [])
  @timeout = timeout
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



5
6
7
# File 'lib/http_client_generator/resources_definition.rb', line 5

def resources
  @resources
end

Instance Method Details

#namespace(_name = nil, &block) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/http_client_generator/resources_definition.rb', line 44

def namespace(_name = nil, &block)
  namespaced_definition = ResourcesDefinition.new(
    @base, @req_plugs.dup, { head: @resp_head_plugs.dup, body: @resp_plugs.dup }, @timeout
  )
  namespaced_definition.instance_eval(&block)
  @resources += namespaced_definition.resources
end

#req_plug(plug, *args, only: nil, except: nil, **kwargs) ⇒ Object



28
29
30
# File 'lib/http_client_generator/resources_definition.rb', line 28

def req_plug(plug, *args, only: nil, except: nil, **kwargs)
  @req_plugs << build_plug_entry(plug, *args, only: only, except: except, **kwargs)
end

#resp_head_plug(plug, *args, only: nil, except: nil, **kwargs) ⇒ Object



36
37
38
# File 'lib/http_client_generator/resources_definition.rb', line 36

def resp_head_plug(plug, *args, only: nil, except: nil, **kwargs)
  @resp_head_plugs << build_plug_entry(plug, *args, only: only, except: except, **kwargs)
end

#resp_plug(plug, *args, only: nil, except: nil, **kwargs) ⇒ Object



32
33
34
# File 'lib/http_client_generator/resources_definition.rb', line 32

def resp_plug(plug, *args, only: nil, except: nil, **kwargs)
  @resp_plugs << build_plug_entry(plug, *args, only: only, except: except, **kwargs)
end

#timeout(value = nil, **options) ⇒ Object



40
41
42
# File 'lib/http_client_generator/resources_definition.rb', line 40

def timeout(value = nil, **options)
  @timeout = TimeoutNormalizer.call(value, **options)
end