luna_park 0.11.5 → 0.11.6
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +2 -2
- data/lib/luna_park/errors/base.rb +11 -11
- data/lib/luna_park/extensions/has_errors.rb +8 -14
- data/lib/luna_park/http/response.rb +2 -0
- data/lib/luna_park/mappers/codirectional.rb +1 -1
- data/lib/luna_park/notifiers/log.rb +1 -1
- data/lib/luna_park/use_cases/scenario.rb +15 -11
- data/lib/luna_park/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4db92d2cf17231ba0d96f4071b636b0bd91f98d7125b49268eeadd49cb712a76
|
|
4
|
+
data.tar.gz: ea8d7bdaf649dc04f2343296ec24f234bfd1e5cd9110b93bc33a3d405a53d1cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 63e880268e5a55561867f67f0a71b8804bbf36671c1fb2cc98cd3a17cdd84264e850fe739919864d3fc88e7f74056fabba73e89781a8766f4a239096e885278f
|
|
7
|
+
data.tar.gz: 41e777a88fb0e95517ea2a5644454ffeedcbd902879040baa2149f82e63f48ef77779aef95088fe15b29e89ae33daf5163b0bdb9530a345b02ed506bb926026f
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ 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
|
+
|
|
7
15
|
## [0.11.5] - 2022-09-27
|
|
8
16
|
Changed
|
|
9
17
|
- Added `.custom_error` method to `Extensions::HasError` to define errors with a custom superclass
|
data/Gemfile.lock
CHANGED
|
@@ -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',
|
|
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 :
|
|
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
|
|
70
|
+
# @param i18n [String] - internationalization key
|
|
71
71
|
# @return [NilClass]
|
|
72
|
-
def message(txt = nil, i18n_key: nil, &default_message_block)
|
|
73
|
-
@
|
|
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
|
|
80
|
-
inheritor.message(i18n_key: i18n_key, &
|
|
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',
|
|
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
|
|
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.
|
|
240
|
+
self.class.__default_message_block__&.call(details)
|
|
241
241
|
end
|
|
242
242
|
end
|
|
243
243
|
end
|
|
@@ -65,17 +65,14 @@ module LunaPark
|
|
|
65
65
|
# class Service
|
|
66
66
|
# include LunaPark::Extensions::HasErrors
|
|
67
67
|
#
|
|
68
|
-
# business_error
|
|
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
|
-
|
|
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
|
##
|
|
@@ -95,11 +92,8 @@ module LunaPark
|
|
|
95
92
|
# tech_error = Service::TechError.new
|
|
96
93
|
# tech_error.is_a? LunaPark::Errors::System # => true
|
|
97
94
|
# tech_error.message # => 'Error message'
|
|
98
|
-
def system_error(title, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
|
|
99
|
-
|
|
100
|
-
error_class.message(txt, i18n_key: i18n_key, &default_message_block)
|
|
101
|
-
error_class.notify(notify)
|
|
102
|
-
const_set(error_class_name(title), error_class)
|
|
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
|
|
103
97
|
end
|
|
104
98
|
|
|
105
99
|
##
|
|
@@ -121,7 +115,7 @@ module LunaPark
|
|
|
121
115
|
# custom_error.is_a? BaseError # => true
|
|
122
116
|
# custom_error.description # => 'Error message'
|
|
123
117
|
# rubocop:disable Metrics/ParameterLists
|
|
124
|
-
def custom_error(title, inherit_from, txt = nil, i18n_key: nil, notify: nil, &default_message_block)
|
|
118
|
+
def custom_error(title, inherit_from, txt = nil, i18n_key: nil, i18n: nil, notify: nil, &default_message_block)
|
|
125
119
|
unless inherit_from < Errors::Base
|
|
126
120
|
raise ArgumentError, 'inherit_from must be a superclass of LunaPark::Errors::Base'
|
|
127
121
|
end
|
|
@@ -130,8 +124,8 @@ module LunaPark
|
|
|
130
124
|
error_class.inherited(inherit_from)
|
|
131
125
|
error_class.notify(notify) unless notify.nil?
|
|
132
126
|
|
|
133
|
-
message_present = ![txt, i18n_key, default_message_block].all?(&:nil?)
|
|
134
|
-
error_class.message(txt,
|
|
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
|
|
135
129
|
|
|
136
130
|
const_set(error_class_name(title), error_class)
|
|
137
131
|
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 &&
|
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
299
|
+
def rescue_exception
|
|
296
300
|
yield
|
|
297
301
|
rescue Errors::Base => e
|
|
298
302
|
@state = FAIL
|
data/lib/luna_park/version.rb
CHANGED