lazy_ant 0.6.2 → 0.7.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: 2acfc7400887f4711bc16dd2edbd333ecce3da5a
4
- data.tar.gz: 48aaa27d8b7999ddcfd282583461057751d17571
3
+ metadata.gz: 598e3d76854ce65e8fadb525903fbd19e1e866d6
4
+ data.tar.gz: 3f9584c20b54c99e57dc5d9ba16e31683bb4ef1b
5
5
  SHA512:
6
- metadata.gz: 64d74e9204f9ccb73febdb20d6acb3b66a69a804c1d5b8711acdab9b6efc50e31967a41345fd266866fd1ad2e7bb07e774f6e929ca0b66eb50c639e58761ccdb
7
- data.tar.gz: 831217e60ffddb9416d74203411676bc2ac8dff7d97fce02c41e66837171a131e2c1f0aa6b1dcc96b2a91bbe7d006da3ff344ddb93070ed6a86da99435d410c9
6
+ metadata.gz: 4e9843c42f93a4b4b0d1f5fe4d5a6454d5261014423bcc1cbea5180866376a45f0d3a98782d737ddbe52819e15a89076153cd6c91b02de7ccacfbec0b150dc37
7
+ data.tar.gz: 3f56b1754d512ef6fb3664847e0147e5f31b3593e0621ffac9a373654cd96a1006497ddc0b37d84473ffe336ea6e83b75c6dfe6c76d2d4cf094a9fc398e04fec
@@ -1,7 +1,10 @@
1
+ AllCops:
2
+ Exclude:
3
+ - '*.gemspec'
4
+ - 'vendor/bundle/**/*'
1
5
  Metrics/LineLength:
2
6
  Exclude:
3
7
  - 'spec/**/*'
4
- - '*.gemspec'
5
8
  Style/Documentation:
6
9
  Exclude:
7
10
  - 'lib/lazy_ant/config.rb'
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.5
4
- - 2.2.2
3
+ - 2.2.5
4
+ - 2.3.1
5
5
  cache: bundler
6
- before_install: gem install bundler -v 1.10.5
6
+ before_install: gem install bundler
7
7
  script:
8
8
  - bundle exec rubocop
9
9
  - bundle exec rake spec
data/Guardfile CHANGED
@@ -15,7 +15,7 @@ guard :rspec, cmd: 'bundle exec rspec' do
15
15
  dsl.watch_spec_files_for(ruby.lib_files)
16
16
  end
17
17
 
18
- guard :rubocop, cli: '--auto-correct' do
18
+ guard :rubocop, cli: '--auto-correct -D --except Lint/Debugger' do
19
19
  watch(/.+\.rb$/)
20
20
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
21
21
  end
data/README.md CHANGED
@@ -62,6 +62,9 @@ and use it:
62
62
  client = MyApiClient.new do |config|
63
63
  config.client_token = 'hello'
64
64
  config.client_secret = 'world'
65
+
66
+ config.logger
67
+ # config.logger Logger.new, { some: 'option' }
65
68
  end
66
69
 
67
70
  client.user.find(1)
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  if spec.respond_to?(:metadata)
20
20
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
21
  else
22
- fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
23
  end
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -1,9 +1,12 @@
1
1
  module LazyAnt
2
2
  class Config
3
+ attr_reader :connection_callbacks
4
+
3
5
  def initialize
4
6
  self.class.keys.each do |var, options|
5
7
  instance_variable_set(var, options[:default])
6
8
  end
9
+ @connection_callbacks = []
7
10
  end
8
11
 
9
12
  def deprecated(method, instead)
@@ -16,7 +19,14 @@ module LazyAnt
16
19
  end
17
20
 
18
21
  def validate(val)
19
- fail ArgumentError unless val == true || val == false
22
+ raise ArgumentError unless val == true || val == false
23
+ end
24
+
25
+ def logger(instance = nil, options = {})
26
+ @connection_callbacks << lambda do |con|
27
+ args = [:logger, instance, options].compact
28
+ con.send(:response, *args)
29
+ end
20
30
  end
21
31
 
22
32
  class << self
@@ -9,9 +9,12 @@ module LazyAnt
9
9
  include Endpoint
10
10
  include Connection
11
11
 
12
- def initialize(&_block)
12
+ def initialize
13
13
  yield config if block_given?
14
14
  config.freeze
15
+ config.connection_callbacks.each do |callback|
16
+ instance_callbacks.push callback
17
+ end
15
18
  end
16
19
 
17
20
  module ClassMethods
@@ -5,7 +5,6 @@ module LazyAnt
5
5
  module DSL
6
6
  module Connection
7
7
  extend ActiveSupport::Concern
8
- attr_reader :default_params
9
8
 
10
9
  def connection
11
10
  return @connection if @connection
@@ -14,11 +13,15 @@ module LazyAnt
14
13
  use_converter(con)
15
14
  con.response response_type
16
15
  con.response :raise_error
16
+ callbacks.each { |callback| instance_exec(con, &callback) }
17
17
  con.adapter Faraday.default_adapter
18
- instance_exec(con, &default_callback) if default_callback
19
18
  end
20
19
  end
21
20
 
21
+ def callbacks
22
+ ([default_callback] + instance_callbacks).compact
23
+ end
24
+
22
25
  def use_converter(con)
23
26
  if converter_block
24
27
  con.use LazyAnt::Converter, &converter_block
@@ -57,6 +60,11 @@ module LazyAnt
57
60
  @parent && @parent.response_type || :json
58
61
  end
59
62
 
63
+ def instance_callbacks
64
+ @instance_callbacks ||=
65
+ @parent && @parent.instance_callbacks || []
66
+ end
67
+
60
68
  module ClassMethods
61
69
  def base_url(url = nil, &block)
62
70
  if block_given?
@@ -5,7 +5,7 @@ module LazyAnt
5
5
 
6
6
  module ClassMethods
7
7
  def group(name, &block)
8
- base = self.respond_to?(:name) ? self.name : nil
8
+ base = respond_to?(:name) ? self.name : nil
9
9
  group_name = [base, name].compact.join('.')
10
10
  group_class = Class.new(LazyAnt::Group) do
11
11
  self.name = group_name
@@ -31,7 +31,7 @@ module LazyAnt
31
31
 
32
32
  def validate!
33
33
  params.select { |_k, v| v[:required] }.each do |k, _v|
34
- fail ArgumentError, "params[:#{k}] is required!" unless @query[k]
34
+ raise ArgumentError, "params[:#{k}] is required!" unless @query[k]
35
35
  end
36
36
  end
37
37
 
@@ -41,7 +41,7 @@ module LazyAnt
41
41
  arg_names = url.scan(/:([\w_]+)/).map(&:first)
42
42
  arg_names.each do |k|
43
43
  arg = args.shift
44
- fail ArgumentError, "missing required key :#{k}" unless arg
44
+ raise ArgumentError, "missing required key :#{k}" unless arg
45
45
  url.gsub!(/:#{k}/, arg.to_s)
46
46
  end
47
47
  url
@@ -1,3 +1,3 @@
1
1
  module LazyAnt
2
- VERSION = '0.6.2'
2
+ VERSION = '0.7.0'.freeze
3
3
  end
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.6.2
4
+ version: 0.7.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-10-21 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -272,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
272
  version: '0'
273
273
  requirements: []
274
274
  rubyforge_project:
275
- rubygems_version: 2.2.2
275
+ rubygems_version: 2.5.1
276
276
  signing_key:
277
277
  specification_version: 4
278
278
  summary: Generate an api client easily.