Module: LazyAnt::DSL::Connection

Extended by:
ActiveSupport::Concern
Included in:
LazyAnt::DSL, Endpoint
Defined in:
lib/lazy_ant/dsl/connection.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_paramsObject (readonly)

Returns the value of attribute default_params.



8
9
10
# File 'lib/lazy_ant/dsl/connection.rb', line 8

def default_params
  @default_params
end

Instance Method Details

#connectionObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lazy_ant/dsl/connection.rb', line 10

def connection
  return @connection if @connection
  @connection = Faraday.new(base_url) do |con|
    con.request request_type
    use_converter(con)
    con.response response_type
    con.response :raise_error
    con.adapter Faraday.default_adapter
    instance_exec(con, &default_callback) if default_callback
  end
end

#converter_blockObject



36
37
38
39
40
# File 'lib/lazy_ant/dsl/connection.rb', line 36

def converter_block
  @converter_block ||=
    self.class.instance_variable_get(:@converter_block) ||
    @parent && @parent.converter_block
end

#converter_nameObject



42
43
44
45
46
# File 'lib/lazy_ant/dsl/connection.rb', line 42

def converter_name
  @coverter_name ||=
    self.class.instance_variable_get(:@converter_name) ||
    @parent && @parent.converter_name
end

#default_callbackObject



30
31
32
33
34
# File 'lib/lazy_ant/dsl/connection.rb', line 30

def default_callback
  @default_callback ||=
    self.class.instance_variable_get(:@default_callback) ||
    @parent && @parent.default_callback
end

#request_typeObject



48
49
50
51
52
# File 'lib/lazy_ant/dsl/connection.rb', line 48

def request_type
  @request_type ||=
    self.class.instance_variable_get(:@request_type) ||
    @parent && @parent.request_type || :json
end

#response_typeObject



54
55
56
57
58
# File 'lib/lazy_ant/dsl/connection.rb', line 54

def response_type
  @response_type ||=
    self.class.instance_variable_get(:@response_type) ||
    @parent && @parent.response_type || :json
end

#use_converter(con) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/lazy_ant/dsl/connection.rb', line 22

def use_converter(con)
  if converter_block
    con.use LazyAnt::Converter, &converter_block
  elsif converter_name
    con.response converter_name
  end
end