luna_park 0.11.4 → 0.11.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25c15d875ee58d0d61589f2041e81c65eeccde628e8a07c584722fc69865741a
4
- data.tar.gz: 27f13cbf3d1073f651a13c714092e1ebac28b4b9e3c8eb0dcfcc2fdec4b0009e
3
+ metadata.gz: 4db92d2cf17231ba0d96f4071b636b0bd91f98d7125b49268eeadd49cb712a76
4
+ data.tar.gz: ea8d7bdaf649dc04f2343296ec24f234bfd1e5cd9110b93bc33a3d405a53d1cc
5
5
  SHA512:
6
- metadata.gz: e747fa427d30d6b64d3cd4300beb67d27b080b41de497f959caa05b719b94845178c8fa53944261a81fcedb9fb31950a5ba53d01ae87bf529b9eba16a4e92b9a
7
- data.tar.gz: 0432dfffa7d6702f79fdfa2abdf68b4fee5d9d6fdd4f0864e01fd7829873db8c32a2656b72479f4735d0423256aecb5f97e55c03b5daa3b9c513036062be336f
6
+ metadata.gz: 63e880268e5a55561867f67f0a71b8804bbf36671c1fb2cc98cd3a17cdd84264e850fe739919864d3fc88e7f74056fabba73e89781a8766f4a239096e885278f
7
+ data.tar.gz: 41e777a88fb0e95517ea2a5644454ffeedcbd902879040baa2149f82e63f48ef77779aef95088fe15b29e89ae33daf5163b0bdb9530a345b02ed506bb926026f
data/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.11.6] - 2021-10-06
8
+ Changed
9
+ - in `UseCases::Scenario` now abstract method is `#perform` - not `call!`. It is backward-compatible change: `call!` still works as abstract, and public interface was not changed.
10
+
11
+ Added
12
+ - returned old aliases fail falure to scenarios
13
+ - add short alias for exceptions (`i18n:` instead of `i18n_key:`)
14
+
15
+ ## [0.11.5] - 2022-09-27
16
+ Changed
17
+ - Added `.custom_error` method to `Extensions::HasError` to define errors with a custom superclass
18
+ - Added `#inject` method to `Extensions::Injector` - dependencies setter that allows you to create method chains
19
+
7
20
  ## [0.11.4] - 2022-07-11
8
21
  Changed
9
22
  - allow require Notifiers::Sentry when sentry-ruby version >= 4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luna_park (0.11.4)
4
+ luna_park (0.11.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -179,4 +179,4 @@ DEPENDENCIES
179
179
  yard (~> 0.9)
180
180
 
181
181
  BUNDLED WITH
182
- 2.1.4
182
+ 2.2.30
@@ -17,7 +17,7 @@ module LunaPark
17
17
  # @example Fatalism class
18
18
  # module Errors
19
19
  # class Fatalism < LunaPark::Errors::Base
20
- # message 'You cannot change your destiny', i18n_key: 'errors.fatalism'
20
+ # message 'You cannot change your destiny', i18n: 'errors.fatalism'
21
21
  # notify: :info
22
22
  # end
23
23
  # end
@@ -50,7 +50,7 @@ module LunaPark
50
50
  # Proc, that receives details hash: { detail_key => detail_value }
51
51
  #
52
52
  # @private
53
- attr_reader :default_message_block
53
+ attr_reader :__default_message_block__
54
54
 
55
55
  # Specifies the expected behavior of the error handler if an error
56
56
  # instance of this class is raised
@@ -67,17 +67,17 @@ module LunaPark
67
67
  # Specify default error message
68
68
  #
69
69
  # @param txt [String] - text of message
70
- # @param i18n_key [String] - internationalization key
70
+ # @param i18n [String] - internationalization key
71
71
  # @return [NilClass]
72
- def message(txt = nil, i18n_key: nil, &default_message_block)
73
- @default_message_block = block_given? ? default_message_block : txt && ->(_) { txt }
74
- @i18n_key = i18n_key
72
+ def message(txt = nil, i18n_key: nil, i18n: nil, &default_message_block)
73
+ @__default_message_block__ = block_given? ? default_message_block : txt && ->(_) { txt }
74
+ @i18n_key = i18n || i18n_key
75
75
  nil
76
76
  end
77
77
 
78
78
  def inherited(inheritor)
79
- if default_message_block
80
- inheritor.message(i18n_key: i18n_key, &default_message_block)
79
+ if __default_message_block__
80
+ inheritor.message(i18n_key: i18n_key, &__default_message_block__)
81
81
  elsif i18n_key
82
82
  inheritor.message(i18n_key: i18n_key)
83
83
  end
@@ -186,7 +186,7 @@ module LunaPark
186
186
  # # frost: Прости Кузьма, замерзли ноги!
187
187
  #
188
188
  # class FrostError < LunaPark::Errors::Base
189
- # message 'Forgive Kuzma, my feet froze', i18n_key: 'errors.frost'
189
+ # message 'Forgive Kuzma, my feet froze', i18n: 'errors.frost'
190
190
  # end
191
191
  #
192
192
  # error = FrostError.new
@@ -207,7 +207,7 @@ module LunaPark
207
207
  # # wrong_answer: Die richtige Antwort ist '%{correct}', nicht '%{wrong}'
208
208
  #
209
209
  # class WrongAnswerError < LunaPark::Errors::Base
210
- # message i18n_key: 'errors.wrong_answer'
210
+ # message i18n: 'errors.wrong_answer'
211
211
  # end
212
212
  #
213
213
  # error = WrongAnswerError.new(correct: 42, wrong: 420)
@@ -237,7 +237,7 @@ module LunaPark
237
237
 
238
238
  # @return [String] - Default message
239
239
  def build_default_message
240
- self.class.default_message_block&.call(details)
240
+ self.class.__default_message_block__&.call(details)
241
241
  end
242
242
  end
243
243
  end
@@ -43,10 +43,10 @@ module LunaPark
43
43
  # class Service
44
44
  # include LunaPark::Extensions::HasErrors
45
45
  #
46
- # class CustomError < LunaPark::Errors::Business; end
46
+ # class LogicError < LunaPark::Errors::Business; end
47
47
  # end
48
48
  #
49
- # Service.new.error :custom_error # => raise CustomError
49
+ # Service.new.error :logic_error # => raise LogicError
50
50
  #
51
51
  # @param title [Symbol|String] - Title of error
52
52
  # @param msg [String] - Message of error
@@ -65,17 +65,14 @@ module LunaPark
65
65
  # class Service
66
66
  # include LunaPark::Extensions::HasErrors
67
67
  #
68
- # business_error :logic_error, { (1 + 1).to_s }
68
+ # business_error(:logic_error) { (1 + 1).to_s }
69
69
  # end
70
70
  #
71
71
  # logic_error = Service::LogicError.new
72
72
  # logic_error.is_a? LunaPark::Errors::Business # => true
73
73
  # logic_error.message # => '2'
74
- def business_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
75
- error_class = Class.new(Errors::Business)
76
- error_class.message(txt, i18n_key: i18n_key, &default_message_block)
77
- error_class.notify(notify)
78
- const_set(error_class_name(title), error_class)
74
+ def business_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists
75
+ custom_error title, Errors::Business, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block
79
76
  end
80
77
 
81
78
  ##
@@ -89,18 +86,50 @@ module LunaPark
89
86
  # class Service
90
87
  # include LunaPark::Extensions::HasErrors
91
88
  #
92
- # system_error :tech_error, 'Custom message'
89
+ # system_error :tech_error, 'Error message'
93
90
  # end
94
91
  #
95
92
  # tech_error = Service::TechError.new
96
93
  # tech_error.is_a? LunaPark::Errors::System # => true
97
- # tech_error.message # => 'Custom message'
98
- def system_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
99
- error_class = Class.new(Errors::System)
100
- error_class.message(txt, i18n_key: i18n_key, &default_message_block)
101
- error_class.notify(notify)
94
+ # tech_error.message # => 'Error message'
95
+ def system_error(title, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block) # rubocop:disable Metrics/ParameterLists
96
+ custom_error title, Errors::System, txt, i18n: i18n || i18n_key, notify: notify, &default_message_block
97
+ end
98
+
99
+ ##
100
+ # Define error with a custom superclass.
101
+ # The superclass must be inherited from LunaPark::Errors::Base.
102
+ #
103
+ # @example
104
+ # class BaseError < LunaPark::Errors::Business
105
+ # alias description message
106
+ # end
107
+ #
108
+ # class Service
109
+ # include LunaPark::Extensions::HasErrors
110
+ #
111
+ # custom_error :custom_error, BaseError, 'Error message'
112
+ # end
113
+ #
114
+ # custom_error = Service::CustomError.new
115
+ # custom_error.is_a? BaseError # => true
116
+ # custom_error.description # => 'Error message'
117
+ # rubocop:disable Metrics/ParameterLists
118
+ def custom_error(title, inherit_from, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block)
119
+ unless inherit_from < Errors::Base
120
+ raise ArgumentError, 'inherit_from must be a superclass of LunaPark::Errors::Base'
121
+ end
122
+
123
+ error_class = Class.new(inherit_from)
124
+ error_class.inherited(inherit_from)
125
+ error_class.notify(notify) unless notify.nil?
126
+
127
+ message_present = ![txt, i18n || i18n_key, default_message_block].all?(&:nil?)
128
+ error_class.message(txt, i18n: i18n || i18n_key, &default_message_block) if message_present
129
+
102
130
  const_set(error_class_name(title), error_class)
103
131
  end
132
+ # rubocop:enable Metrics/ParameterLists
104
133
 
105
134
  ##
106
135
  # Get error class name
@@ -191,6 +191,19 @@ module LunaPark
191
191
  def dependencies=(value)
192
192
  @dependencies = Dependencies.wrap(value)
193
193
  end
194
+
195
+ ##
196
+ # Set dependencies, returns `self` to allow chaining
197
+ # Don't forget to override <b>all</b> dependencies.
198
+ #
199
+ # use_case
200
+ # .inject({ repo: -> { Fake::Repo.new }})
201
+ # .call
202
+ #
203
+ def inject(value)
204
+ self.dependencies = value
205
+ self
206
+ end
194
207
  end
195
208
  end
196
209
  end
@@ -371,6 +371,8 @@ module LunaPark
371
371
 
372
372
  # Two response should be equal, if their attributes (request, code, body, headers, cookies) match.
373
373
  def ==(other)
374
+ return false unless other.is_a? Response
375
+
374
376
  code == other.code &&
375
377
  body == other.body &&
376
378
  headers == other.headers &&
@@ -16,7 +16,7 @@ module LunaPark
16
16
  # map attr: [:charge, :currency], row: :charge_currency # using aliased args
17
17
  # map :comment
18
18
  # end
19
- #
19
+ #
20
20
  # mapper = Mappers::Transaction
21
21
  #
22
22
  # attrs = { charge: { amount: 10, currency: 'USD' }, comment: 'Foobar' }
@@ -153,7 +153,7 @@ module LunaPark
153
153
  message = with
154
154
  return details unless message.respond_to?(:details)
155
155
 
156
- message.details.merge(details) do |_, object_value, message_value|
156
+ (message.details || {}).merge(details || {}) do |_, object_value, message_value|
157
157
  { message: message_value, object: object_value }
158
158
  end
159
159
  end
@@ -28,7 +28,7 @@ module LunaPark
28
28
  # class CreateUser < Scenario
29
29
  # attr_accessor :email, :password
30
30
  #
31
- # def call!
31
+ # def perform
32
32
  # user = Entities::User.new
33
33
  # user.email = email
34
34
  # user.password = Service::Encode.call(password)
@@ -80,7 +80,7 @@ module LunaPark
80
80
  # @example on fail
81
81
  # class Fail < Errors::Business; end
82
82
  # class FailScenario < Scenario
83
- # def call!
83
+ # def perform
84
84
  # raise Fail
85
85
  # :result
86
86
  # end
@@ -108,7 +108,7 @@ module LunaPark
108
108
  #
109
109
  # @example on success
110
110
  # class SuccessScenario < Scenario
111
- # def call!
111
+ # def perform
112
112
  # :result
113
113
  # end
114
114
  # end
@@ -131,7 +131,7 @@ module LunaPark
131
131
  # class SayHello < Scenario
132
132
  # attr_accessor :first_name, :last_name
133
133
  #
134
- # def call!
134
+ # def perform
135
135
  # t('hello_my_nme_is', first_name: first_name, last_name: last_name)
136
136
  # end
137
137
  # end
@@ -159,6 +159,10 @@ module LunaPark
159
159
  @state = INIT
160
160
  end
161
161
 
162
+ def call!
163
+ perform
164
+ end
165
+
162
166
  # You must define this action and describe all business logic here.
163
167
  # When you run this method - it run as is, and does not change scenario instance.
164
168
  #
@@ -168,7 +172,7 @@ module LunaPark
168
172
  # class Shot < Scenario
169
173
  # attr_accessor :lucky_mode
170
174
  #
171
- # def call!
175
+ # def perform
172
176
  # raise YouDied, 'Always something went wrong' unless lucky_mode
173
177
  # 'All good'
174
178
  # end
@@ -186,13 +190,13 @@ module LunaPark
186
190
  # @example Russian roulette
187
191
  # # `.call!` usually use for "scenario in scenario"
188
192
  # class RussianRoulette < Scenario
189
- # def call!
193
+ # def perform
190
194
  # [true, true, true, true, true, false].shuffle do |bullet|
191
195
  # Shot.call! lucky_mode: bullet
192
196
  # end
193
197
  # end
194
198
  # end
195
- def call!
199
+ def perform
196
200
  raise Errors::AbstractMethod
197
201
  end
198
202
 
@@ -207,7 +211,7 @@ module LunaPark
207
211
  # class Shot < Scenario
208
212
  # attr_accessor :lucky_mode
209
213
  #
210
- # def call!
214
+ # def perform
211
215
  # raise YouDied, 'Always something went wrong' unless lucky_mode
212
216
  # 'All good'
213
217
  # end
@@ -237,7 +241,7 @@ module LunaPark
237
241
  # end
238
242
  # end
239
243
  def call
240
- catch { @data = call! }
244
+ rescue_exception { @data = call! }
241
245
  self
242
246
  end
243
247
 
@@ -278,7 +282,7 @@ module LunaPark
278
282
  # class Foobar < Scenario
279
283
  # notify_with Notifier::Bugsnag
280
284
  #
281
- # def call!
285
+ # def perform
282
286
  # true
283
287
  # end
284
288
  # end
@@ -292,7 +296,7 @@ module LunaPark
292
296
 
293
297
  private
294
298
 
295
- def catch
299
+ def rescue_exception
296
300
  yield
297
301
  rescue Errors::Base => e
298
302
  @state = FAIL
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LunaPark
4
- VERSION = '0.11.4'
4
+ VERSION = '0.11.6'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luna_park
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kudrin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-30 00:00:00.000000000 Z
12
+ date: 2022-10-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bugsnag