faraday-sunset 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -1
  3. data/lib/faraday/sunset.rb +51 -5
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a4675801498e8f952508acc69b12825f110e1a7
4
- data.tar.gz: bbb3c14239abbb25c0c24f67f2776d8e1d1b69e8
3
+ metadata.gz: f6342c56ae356cacca2ee93a523cfd41ae6fb3a2
4
+ data.tar.gz: 51c570dc5dd9a71c7c4ed7b5429c61f491d4bc19
5
5
  SHA512:
6
- metadata.gz: ae1f5afed75ae1d006fdec6e9dfb2deb2d5a49cce5993c778e9f12dc29246ab215b8d6f28c36075c82cde1dea3414836748eae5bed5dc48543f75e2679413c09
7
- data.tar.gz: ebdbb6af58e65b1154acec7e0afc39c10ad33b3faee4b637fccc19d9846000f8e5098bab3f9ad64160cf2d04212e4e2072e24833c8bda6fc4a8a1c7be16491cb
6
+ metadata.gz: e0eafaceef2453b4006b6c59431f744b3980779ccf767a8be85cd43a656cc2a08aac97a3a742cec089d1f922cf5ca365f574297738a783f0822dc5e2f7d86a35
7
+ data.tar.gz: c59f5b3dea7b9f9fcd2400e03e1ba420ddcf06cd8bee220805951c4d82098a9060e10c12226d52176b29d4d56f251a55e90d33329cdd767406c634d2fa40e973
data/README.md CHANGED
@@ -38,10 +38,24 @@ connection = Faraday.new(url: '...') do |conn|
38
38
  conn.response :sunset, active_support: true
39
39
  # or
40
40
  conn.response :sunset, logger: Rails.logger
41
+ # or
42
+ conn.response :sunset, rollbar: true
43
+ # or combine:
44
+ conn.response :sunset, rollbar: :auto, active_support: true, logger: Rails.logger
41
45
  end
42
46
  ```
43
47
 
44
- You can [configure `ActiveSupport::Deprecation`][active-support-deprecation] to warn in a few different ways, or pass in any object that acts a bit like a Rack logger, Rails logger, or anything with a `warn` method that takes a string.
48
+ For `logger`, You can pass in any object that acts a bit like a Rack logger, Rails logger, or anything with a `warn` method that takes a string.
49
+
50
+ You can [configure `ActiveSupport::Deprecation`][active-support-deprecation] to warn in 3 ways:
51
+ - `true` - throw warnings on sunsetted endpoints, and throw an error if active-support is missing from the project
52
+ - `false` - ignore active-support
53
+ - `:auto` - throw warnings on sunsetted endpoints, and ignore if active-support is missing from the project
54
+
55
+ You can [configure `Rollbar`][rollbar] in 3 ways:
56
+ - `true` - throw warnings on sunsetted endpoints, and throw an error if active-support is missing from the project
57
+ - `false` - ignore rollbar
58
+ - `:auto` - throw warnings on sunsetted endpoints, and ignore if Rollbar is missing from the project
45
59
 
46
60
  [active-support-deprecation]: http://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html
47
61
 
@@ -9,10 +9,11 @@ module Faraday
9
9
  # @param [Type] app describe app
10
10
  # @param [Hash] options = {}
11
11
  # @return void
12
- def initialize(app, active_support: nil, logger: nil)
12
+ def initialize(app, active_support: nil, logger: nil, rollbar: nil)
13
13
  super(app)
14
14
  @active_support = active_support
15
15
  @logger = logger
16
+ @rollbar = rollbar
16
17
  end
17
18
 
18
19
  # @param [Faraday::Env] no idea what this does
@@ -46,18 +47,63 @@ module Faraday
46
47
 
47
48
  def send_warning!(warning)
48
49
  warned = false
49
- if @active_support
50
- ActiveSupport::Deprecation.warn(warning)
51
- warned = true
50
+
51
+ if @active_support == :auto
52
+ warned = report_active_support(warned, warning)
53
+ elsif @active_support == true
54
+ warned = report_active_support!(warning)
52
55
  end
56
+
53
57
  if @logger && @logger.respond_to?(:warn)
54
58
  @logger.warn(warning)
55
59
  warned = true
56
60
  end
61
+
62
+ if @rollbar == :auto
63
+ warned = report_rollbar(warned, warning)
64
+ elsif @rollbar == true
65
+ warned = report_rollbar!(warning)
66
+ end
67
+
57
68
  unless warned
58
- raise NoOutputForWarning, "Pass active_support: true, or logger: ::Logger.new when registering middleware"
69
+ raise NoOutputForWarning, "Pass active_support: (true|false|:auto), rollbar: (true|false|:auto), or logger: ::Logger.new when registering middleware"
59
70
  end
60
71
  end
72
+
73
+ private
74
+
75
+ def report_rollbar!(warning)
76
+ Rollbar.warning(warning)
77
+ # return true to set :warned
78
+ true
79
+ end
80
+
81
+ def report_active_support!(warning)
82
+ ActiveSupport::Deprecation.warn(warning)
83
+ # return true to set :warned
84
+ true
85
+ end
86
+
87
+ # :auto methods
88
+ # do not raise errors if gems are missing
89
+ def report_rollbar(warned, warning)
90
+ report_rollbar!(warning)
91
+
92
+ rescue NameError
93
+ # rollbar is not present!
94
+ # do not modify warned if an error is raised
95
+ warned
96
+ end
97
+
98
+ def report_active_support(warned, warning)
99
+ report_active_support!(warning)
100
+
101
+ rescue NameError
102
+ # active_support is not present!
103
+ # do not modify warned if an error is raised - return warned instead
104
+ warned
105
+ end
106
+
61
107
  end
62
108
  end
63
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday-sunset
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Sturgeon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rollbar
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: activesupport
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
159
  version: '0'
146
160
  requirements: []
147
161
  rubyforge_project:
148
- rubygems_version: 2.6.11
162
+ rubygems_version: 2.6.14
149
163
  signing_key:
150
164
  specification_version: 4
151
165
  summary: Automatically detect deprecated HTTP endpoints