lazy_ant 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 896a03bb79a1a9b695a09885267d69c309f6ed8a
4
- data.tar.gz: 1834d0d47a5642f1c8a38a93b4cf252e915d1f0c
3
+ metadata.gz: 247b3876e68914bf1b6c5a5154663d6daaa55281
4
+ data.tar.gz: 676638069bf8ebfaa241dbc026df133f0afbba9c
5
5
  SHA512:
6
- metadata.gz: 2eb5d43ec09f5632c33d1304a41e9a773491197d32c425b9f7ccf8b21d638bebcea8e5b932d3695454b734fd488fb8be302480d6fed92fd8fd877ee853ef5df6
7
- data.tar.gz: 2c4c6a77639767cb02aabb8b1a4a0eab5de2f97449bc7041a3dd8323dfcd9551887814e8796375ef3849058941ef788074e27dca391e5abe280dcda4ccad8a80
6
+ metadata.gz: 98f06eb857d84022e2e7284fe898cfe7a72f0a7daa6e888e306693343694720d29528d14ad9eb8d1d72ca069a2023c0993a16662469b8cbcda3239b49ccdefef
7
+ data.tar.gz: 5b64762ae51ee19ffc7aea754696e61ef2bd1928f8605fdcfca81a3ef9f43d33294449457118784420712a3d455c4c47cf6fe2326a689095b04b7d98d3dded8c
@@ -0,0 +1,18 @@
1
+ module LazyAnt
2
+ # Simple Converter
3
+ #
4
+ # conn.use LazyAnt::Converter do |env|
5
+ # env.body = body['data']
6
+ # end
7
+ #
8
+ class Converter < Faraday::Response::Middleware
9
+ def initialize(app, &block)
10
+ super
11
+ @block = block
12
+ end
13
+
14
+ def on_complete(env)
15
+ @block.call(env)
16
+ end
17
+ end
18
+ end
@@ -10,7 +10,7 @@ module LazyAnt
10
10
  @connection ||= Faraday.new(base_url) do |con|
11
11
  con.request :url_encoded
12
12
  con.request :json
13
- con.response converter_name if converter_name
13
+ use_converter(con)
14
14
  con.response :json
15
15
  con.response :raise_error
16
16
  con.adapter Faraday.default_adapter
@@ -18,12 +18,26 @@ module LazyAnt
18
18
  end
19
19
  end
20
20
 
21
+ def use_converter(con)
22
+ if converter_block
23
+ con.use LazyAnt::Converter, &converter_block
24
+ elsif converter_name
25
+ con.response converter_name
26
+ end
27
+ end
28
+
21
29
  def default_callback
22
30
  @default_callback ||=
23
31
  self.class.instance_variable_get(:@default_callback) ||
24
32
  @parent && @parent.default_callback
25
33
  end
26
34
 
35
+ def converter_block
36
+ @converter_block ||=
37
+ self.class.instance_variable_get(:@converter_block) ||
38
+ @parent && @parent.converter_block
39
+ end
40
+
27
41
  def converter_name
28
42
  @coverter_name ||=
29
43
  self.class.instance_variable_get(:@converter_name) ||
@@ -43,8 +57,9 @@ module LazyAnt
43
57
  end
44
58
  end
45
59
 
46
- def converter(name)
47
- @converter_name = name
60
+ def converter(name = nil, &block)
61
+ return @converter_block = block if block_given?
62
+ @converter_name = name if name
48
63
  end
49
64
 
50
65
  def connection(&block)
@@ -1,3 +1,3 @@
1
1
  module LazyAnt
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
data/lib/lazy_ant.rb CHANGED
@@ -3,3 +3,4 @@ require 'lazy_ant/version'
3
3
  require 'lazy_ant/dsl'
4
4
  require 'lazy_ant/config'
5
5
  require 'lazy_ant/group'
6
+ require 'lazy_ant/converter'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_ant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masarakki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -228,6 +228,7 @@ files:
228
228
  - lazy_ant.gemspec
229
229
  - lib/lazy_ant.rb
230
230
  - lib/lazy_ant/config.rb
231
+ - lib/lazy_ant/converter.rb
231
232
  - lib/lazy_ant/dsl.rb
232
233
  - lib/lazy_ant/dsl/configurable.rb
233
234
  - lib/lazy_ant/dsl/connection.rb