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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfa79de19dfdaeb2246f413fe75c89064077ba6b353af416984169a0c7122130
4
- data.tar.gz: 3b44af84612de0a5eeaa04c960291647ad674336a8f33c50725410849a0bdbd6
3
+ metadata.gz: 4db92d2cf17231ba0d96f4071b636b0bd91f98d7125b49268eeadd49cb712a76
4
+ data.tar.gz: ea8d7bdaf649dc04f2343296ec24f234bfd1e5cd9110b93bc33a3d405a53d1cc
5
5
  SHA512:
6
- metadata.gz: 73cf56e3506c153cf50b1b2f2912d04f2a329ab2b1c97f007e9a0c9bf69265d03cdc0d57e6a7d80f04e9c57aef386cf76c04c16497fc82ac35dc3b5297649bbe
7
- data.tar.gz: 58b2fb6fe676786700d8d86cb1780c70bb9ae530d3a140d3ab25a88db5a8cbf00f342d43aaba9f0b3145e2570c1ac4dd1c3373b2b8bfd93e2e0f40f831e196a7
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luna_park (0.11.5)
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
@@ -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
  ##
@@ -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
- error_class = Class.new(Errors::System)
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, i18n_key: i18n_key, &default_message_block) if message_present
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 &&
@@ -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.5'
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.5
4
+ version: 0.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kudrin