webhook_system 2.4.0 → 2.4.1

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.
@@ -7,7 +7,7 @@ module WebhookSystem
7
7
 
8
8
  # Exception class around non 200 responses
9
9
  class RequestFailed < RuntimeError
10
- def initialize(message, code, error_message=nil)
10
+ def initialize(message, code, error_message = nil)
11
11
  super(message)
12
12
  @code = code
13
13
  @error_message = error_message
@@ -59,8 +59,8 @@ module WebhookSystem
59
59
  response =
60
60
  begin
61
61
  client.builder.build_response(client, request)
62
- rescue RuntimeError => exception
63
- ErrorResponse.new(exception)
62
+ rescue RuntimeError => e
63
+ ErrorResponse.new(e)
64
64
  end
65
65
 
66
66
  log_response(subscription, event, request, response)
@@ -70,16 +70,17 @@ module WebhookSystem
70
70
  def self.ensure_success(response, http_method, subscription)
71
71
  url = subscription.url
72
72
  status = response.status
73
- unless (200..299).cover? status
74
- if subscription.respond_to?(:account_id)
75
- account_info = subscription.account_info
76
- inner = "failed for account #{account_info} with"
77
- else
78
- inner = "failed with"
79
- end
80
- text = "#{http_method} request to #{url} #{inner} code: #{status} and error #{response.body}"
81
- raise RequestFailed.new(text, status, response.body)
73
+ return if (200..299).cover? status
74
+
75
+ if subscription.respond_to?(:account_id)
76
+ account_info = subscription.account_info
77
+ inner = "failed for account #{account_info} with"
78
+ else
79
+ inner = "failed with"
82
80
  end
81
+ text = "#{http_method} request to #{url} #{inner} code: #{status} and error #{response.body}"
82
+ raise RequestFailed.new(text, status, response.body)
83
+
83
84
  end
84
85
 
85
86
  def self.build_request(client, subscription, event)
@@ -104,7 +105,7 @@ module WebhookSystem
104
105
  # We want the even log record to always be created, so we check if we are running inside the transaction,
105
106
  # if we are - we create the record in a separate thread. New Thread means a new DB connection and
106
107
  # ActiveRecord transactions are per connection, which gives us the "transaction jailbreak".
107
- if ActiveRecord::Base.connection.open_transactions == 0
108
+ if ActiveRecord::Base.connection.open_transactions.zero?
108
109
  event_log.save!
109
110
  else
110
111
  Thread.new { event_log.save! }.join
@@ -8,8 +8,8 @@ module WebhookSystem
8
8
 
9
9
  belongs_to :account if defined?(Account)
10
10
 
11
- INLINE_JOB_REGEXP=/^inline:(.*)/
12
- validates :url, presence: true, url: { no_local: true }, if: Proc.new { |a| !a.url.match?(INLINE_JOB_REGEXP) }
11
+ INLINE_JOB_REGEXP = /^inline:(.*)/.freeze
12
+ validates :url, presence: true, url: { no_local: true }, if: proc { |a| !a.url.match?(INLINE_JOB_REGEXP) }
13
13
  validates :secret, presence: true
14
14
 
15
15
  has_many :topics, class_name: 'WebhookSystem::SubscriptionTopic', dependent: :destroy
@@ -18,11 +18,11 @@ module WebhookSystem
18
18
  accepts_nested_attributes_for :topics, allow_destroy: true
19
19
 
20
20
  scope :active, -> { where(active: true) }
21
- scope :for_topic, -> (topic) {
21
+ scope :for_topic, ->(topic) {
22
22
  joins(:topics).where(WebhookSystem::SubscriptionTopic.table_name => { name: topic })
23
23
  }
24
24
 
25
- scope :interested_in_topic, -> (topic) { active.for_topic(topic) }
25
+ scope :interested_in_topic, ->(topic) { active.for_topic(topic) }
26
26
 
27
27
  # Main invocation point for dispatching events, can either be called on the class
28
28
  # or on a relation (ie a scoped down list of subs), will find applicable subs and dispatch to them
@@ -59,7 +59,7 @@ module WebhookSystem
59
59
  new_topics_attributes << {
60
60
  id: topic.id,
61
61
  name: topic.name,
62
- _destroy: !new_topics.include?(topic.name),
62
+ _destroy: new_topics.exclude?(topic.name),
63
63
  }
64
64
  end
65
65
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WebhookSystem
4
- VERSION = '2.4.0'
4
+ VERSION = '2.4.1'
5
5
  end
@@ -36,15 +36,18 @@ Gem::Specification.new do |gem|
36
36
  ```
37
37
  }
38
38
 
39
- gem.add_runtime_dependency 'activesupport', '> 4.2', '< 7.1'
40
- gem.add_runtime_dependency 'activerecord', '> 4.2', '< 7.1'
41
- gem.add_runtime_dependency 'activejob', '> 4.2', '< 7.1'
39
+ gem.required_ruby_version = '> 2.7.0'
40
+ gem.add_runtime_dependency 'activesupport', '> 5.0', '< 7.2'
41
+ gem.add_runtime_dependency 'activerecord', '> 5.0', '< 7.2'
42
+ gem.add_runtime_dependency 'activejob', '> 5.0', '< 7.2'
42
43
  gem.add_runtime_dependency 'faraday', '> 0.9'
43
44
  gem.add_runtime_dependency 'faraday-encoding', '>= 0.0.2', '< 1.0'
44
45
  gem.add_runtime_dependency 'ph_model'
45
46
  gem.add_runtime_dependency 'validate_url', '~> 1.0'
46
47
 
47
- gem.add_development_dependency 'bundler', '> 1.17', '< 2.5'
48
+ gem.add_development_dependency 'bundler', '> 1.17', '< 2.6'
49
+ gem.add_development_dependency 'coveralls_reborn', '~> 0.25'
50
+ gem.add_development_dependency 'simplecov-lcov'
48
51
  gem.add_development_dependency 'rake'
49
52
  gem.add_development_dependency 'rspec', '~> 3.0'
50
53
  gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhook_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Banasik
8
8
  - Mykola Kyryk
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-05-02 00:00:00.000000000 Z
12
+ date: 2023-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -17,60 +17,60 @@ dependencies:
17
17
  requirements:
18
18
  - - ">"
19
19
  - !ruby/object:Gem::Version
20
- version: '4.2'
20
+ version: '5.0'
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '7.1'
23
+ version: '7.2'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">"
29
29
  - !ruby/object:Gem::Version
30
- version: '4.2'
30
+ version: '5.0'
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '7.1'
33
+ version: '7.2'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: activerecord
36
36
  requirement: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.2'
40
+ version: '5.0'
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '7.1'
43
+ version: '7.2'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
47
47
  requirements:
48
48
  - - ">"
49
49
  - !ruby/object:Gem::Version
50
- version: '4.2'
50
+ version: '5.0'
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '7.1'
53
+ version: '7.2'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: activejob
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - ">"
59
59
  - !ruby/object:Gem::Version
60
- version: '4.2'
60
+ version: '5.0'
61
61
  - - "<"
62
62
  - !ruby/object:Gem::Version
63
- version: '7.1'
63
+ version: '7.2'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">"
69
69
  - !ruby/object:Gem::Version
70
- version: '4.2'
70
+ version: '5.0'
71
71
  - - "<"
72
72
  - !ruby/object:Gem::Version
73
- version: '7.1'
73
+ version: '7.2'
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: faraday
76
76
  requirement: !ruby/object:Gem::Requirement
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '1.17'
143
143
  - - "<"
144
144
  - !ruby/object:Gem::Version
145
- version: '2.5'
145
+ version: '2.6'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
@@ -152,7 +152,35 @@ dependencies:
152
152
  version: '1.17'
153
153
  - - "<"
154
154
  - !ruby/object:Gem::Version
155
- version: '2.5'
155
+ version: '2.6'
156
+ - !ruby/object:Gem::Dependency
157
+ name: coveralls_reborn
158
+ requirement: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - "~>"
161
+ - !ruby/object:Gem::Version
162
+ version: '0.25'
163
+ type: :development
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '0.25'
170
+ - !ruby/object:Gem::Dependency
171
+ name: simplecov-lcov
172
+ requirement: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ type: :development
178
+ prerelease: false
179
+ version_requirements: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
156
184
  - !ruby/object:Gem::Dependency
157
185
  name: rake
158
186
  requirement: !ruby/object:Gem::Requirement
@@ -272,11 +300,12 @@ extensions: []
272
300
  extra_rdoc_files: []
273
301
  files:
274
302
  - ".codeclimate.yml"
275
- - ".github/workflows/build.yml"
303
+ - ".coveralls.yml"
304
+ - ".github/workflows/ci.yml"
276
305
  - ".github/workflows/rubocop-challenger.yml"
277
306
  - ".gitignore"
278
- - ".rubocop.hound.yml"
279
307
  - ".rubocop.yml"
308
+ - ".rubocop_challenge.yml"
280
309
  - ".rubocop_todo.yml"
281
310
  - CHANGELOG.md
282
311
  - DEPLOYING.md
@@ -285,14 +314,13 @@ files:
285
314
  - README.md
286
315
  - Rakefile
287
316
  - gemfiles/.bundle/config
288
- - gemfiles/rails_4.2.gemfile
289
- - gemfiles/rails_4.2.gemfile.lock
290
317
  - gemfiles/rails_5.0.gemfile
291
318
  - gemfiles/rails_5.1.gemfile
292
319
  - gemfiles/rails_5.2.gemfile
293
320
  - gemfiles/rails_6.0.gemfile
294
321
  - gemfiles/rails_6.1.gemfile
295
322
  - gemfiles/rails_7.0.gemfile
323
+ - gemfiles/rails_7.1.gemfile
296
324
  - lib/webhook_system.rb
297
325
  - lib/webhook_system/base_event.rb
298
326
  - lib/webhook_system/encoder.rb
@@ -318,17 +346,17 @@ require_paths:
318
346
  - lib
319
347
  required_ruby_version: !ruby/object:Gem::Requirement
320
348
  requirements:
321
- - - ">="
349
+ - - ">"
322
350
  - !ruby/object:Gem::Version
323
- version: '0'
351
+ version: 2.7.0
324
352
  required_rubygems_version: !ruby/object:Gem::Requirement
325
353
  requirements:
326
354
  - - ">="
327
355
  - !ruby/object:Gem::Version
328
356
  version: '0'
329
357
  requirements: []
330
- rubygems_version: 3.1.6
331
- signing_key:
358
+ rubygems_version: 3.4.19
359
+ signing_key:
332
360
  specification_version: 4
333
361
  summary: Webhook system
334
362
  test_files: []
data/.rubocop.hound.yml DELETED
@@ -1,221 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - "vendor/**/*"
4
- - "db/schema.rb"
5
- UseCache: false
6
- Style/CollectionMethods:
7
- Description: Preferred collection methods.
8
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
9
- Enabled: true
10
- PreferredMethods:
11
- collect: map
12
- collect!: map!
13
- find: detect
14
- find_all: select
15
- reduce: inject
16
- Layout/DotPosition:
17
- Description: Checks the position of the dot in multi-line method calls.
18
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
19
- Enabled: true
20
- EnforcedStyle: trailing
21
- SupportedStyles:
22
- - leading
23
- - trailing
24
-
25
- Style/GuardClause:
26
- Description: Check for conditionals that can be replaced with guard clauses
27
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
28
- Enabled: false
29
- MinBodyLength: 1
30
- Style/IfUnlessModifier:
31
- Description: Favor modifier if/unless usage when you have a single-line body.
32
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
33
- Enabled: false
34
- Style/OptionHash:
35
- Description: Don't use option hashes when you can use keyword arguments.
36
- Enabled: false
37
- Style/PercentLiteralDelimiters:
38
- Description: Use `%`-literal delimiters consistently
39
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
40
- Enabled: false
41
- PreferredDelimiters:
42
- "%": "()"
43
- "%i": "()"
44
- "%q": "()"
45
- "%Q": "()"
46
- "%r": "{}"
47
- "%s": "()"
48
- "%w": "()"
49
- "%W": "()"
50
- "%x": "()"
51
- Naming/PredicateName:
52
- Description: Check the names of predicate methods.
53
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
54
- Enabled: true
55
- NamePrefix:
56
- - is_
57
- - has_
58
- - have_
59
- ForbiddenPrefixes:
60
- - is_
61
- Exclude:
62
- - spec/**/*
63
- Style/RaiseArgs:
64
- Description: Checks the arguments passed to raise/fail.
65
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
66
- Enabled: false
67
- EnforcedStyle: exploded
68
- SupportedStyles:
69
- - compact
70
- - exploded
71
- Style/SignalException:
72
- Description: Checks for proper usage of fail and raise.
73
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
74
- Enabled: false
75
- EnforcedStyle: semantic
76
- SupportedStyles:
77
- - only_raise
78
- - only_fail
79
- - semantic
80
- Style/SingleLineBlockParams:
81
- Description: Enforces the names of some block params.
82
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
83
- Enabled: false
84
- Methods:
85
- - reduce:
86
- - a
87
- - e
88
- - inject:
89
- - a
90
- - e
91
- Style/SingleLineMethods:
92
- Description: Avoid single-line methods.
93
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
94
- Enabled: false
95
- AllowIfMethodIsEmpty: true
96
- Style/StringLiterals:
97
- Description: Checks if uses of quotes match the configured preference.
98
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
99
- Enabled: true
100
- EnforcedStyle: double_quotes
101
- SupportedStyles:
102
- - single_quotes
103
- - double_quotes
104
- Style/StringLiteralsInInterpolation:
105
- Description: Checks if uses of quotes inside expressions in interpolated strings
106
- match the configured preference.
107
- Enabled: true
108
- EnforcedStyle: single_quotes
109
- SupportedStyles:
110
- - single_quotes
111
- - double_quotes
112
-
113
-
114
-
115
- Metrics/AbcSize:
116
- Description: A calculated magnitude based on number of assignments, branches, and
117
- conditions.
118
- Enabled: false
119
- Max: 15
120
- Metrics/ClassLength:
121
- Description: Avoid classes longer than 100 lines of code.
122
- Enabled: false
123
- CountComments: false
124
- Max: 100
125
- Metrics/ModuleLength:
126
- CountComments: false
127
- Max: 100
128
- Description: Avoid modules longer than 100 lines of code.
129
- Enabled: false
130
- Metrics/CyclomaticComplexity:
131
- Description: A complexity metric that is strongly correlated to the number of test
132
- cases needed to validate a method.
133
- Enabled: false
134
- Max: 6
135
- Metrics/MethodLength:
136
- Description: Avoid methods longer than 10 lines of code.
137
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
138
- Enabled: false
139
- CountComments: false
140
- Max: 10
141
- Metrics/ParameterLists:
142
- Description: Avoid parameter lists longer than three or four parameters.
143
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
144
- Enabled: false
145
- Max: 5
146
- CountKeywordArgs: true
147
- Metrics/PerceivedComplexity:
148
- Description: A complexity metric geared towards measuring complexity for a human
149
- reader.
150
- Enabled: false
151
- Max: 7
152
- Lint/AssignmentInCondition:
153
- Description: Don't use assignment in conditions.
154
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
155
- Enabled: false
156
- AllowSafeAssignment: true
157
- Style/InlineComment:
158
- Description: Avoid inline comments.
159
- Enabled: false
160
- Naming/AccessorMethodName:
161
- Description: Check the naming of accessor methods for get_/set_.
162
- Enabled: false
163
- Style/Alias:
164
- Description: Use alias_method instead of alias.
165
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
166
- Enabled: false
167
- Style/Documentation:
168
- Description: Document classes and non-namespace modules.
169
- Enabled: false
170
- Style/DoubleNegation:
171
- Description: Checks for uses of double negation (!!).
172
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
173
- Enabled: false
174
- Style/EachWithObject:
175
- Description: Prefer `each_with_object` over `inject` or `reduce`.
176
- Enabled: false
177
- Style/EmptyLiteral:
178
- Description: Prefer literals to Array.new/Hash.new/String.new.
179
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
180
- Enabled: false
181
- Style/ModuleFunction:
182
- Description: Checks for usage of `extend self` in modules.
183
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
184
- Enabled: false
185
- Style/OneLineConditional:
186
- Description: Favor the ternary operator(?:) over if/then/else/end constructs.
187
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
188
- Enabled: false
189
- Style/PerlBackrefs:
190
- Description: Avoid Perl-style regex back references.
191
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
192
- Enabled: false
193
- Style/Send:
194
- Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
195
- may overlap with existing methods.
196
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
197
- Enabled: false
198
- Style/SpecialGlobalVars:
199
- Description: Avoid Perl-style global variables.
200
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
201
- Enabled: false
202
- Style/VariableInterpolation:
203
- Description: Don't interpolate global, instance and class variables directly in
204
- strings.
205
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
206
- Enabled: false
207
- Style/WhenThen:
208
- Description: Use when x then ... for one-line cases.
209
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
210
- Enabled: false
211
- Lint/EachWithObjectArgument:
212
- Description: Check for immutable argument given to each_with_object.
213
- Enabled: true
214
- Lint/SuppressedException:
215
- Description: Don't suppress exception.
216
- StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
217
- Enabled: false
218
-
219
- Lint/LiteralInInterpolation:
220
- Description: Checks for literals used in interpolation.
221
- Enabled: false
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rails", "~> 4.2.11"
6
- gem "sqlite3", "~> 1.3.6"
7
-
8
- gemspec path: "../"