light-service 0.6.1 → 0.7.0

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
  SHA1:
3
- metadata.gz: 25a715c986fab5133c64ef50160f93524bfdcca2
4
- data.tar.gz: 1034f64ec7c50288024a15cce41b29082983941a
3
+ metadata.gz: 20a9e0cfd0b42cb8c0fb35b808f099c50a7ca32f
4
+ data.tar.gz: d8d76249eafe1e4cdeb1830b8b13453905941b7a
5
5
  SHA512:
6
- metadata.gz: 1781b4242bb655bf55e257d65f97a4e4d6bf2d7eb0899bbfc509e10f62fce25d594de73bdcf426490052e3ca54a764c5ae1da049d107693c5a23d69dbe704867
7
- data.tar.gz: 4009c8844215156df49a668a6c953cb60ae577438d35fb3452309fb005084d64b24317de65f4544a4a93af3ebc058edf9174adbbed58c5f227b791d99577bf5c
6
+ metadata.gz: d117cd24d38771a808e1210877387d167a74ad9588c314e34db5903c7b86ded6fdf1760a8a11467051626ea286c017729f82b5f4fe70198d125973b8eb0cc011
7
+ data.tar.gz: e6aaf6e9b0605ad347ad290ef35c2fb9f9afb5a47676b3be01473dd9b57c54ca337c8a5ea5add5541363fecb1c06a187f93a156bb39bc5d72a5082b33172715b
data/.rubocop.yml CHANGED
@@ -9,6 +9,9 @@ AllCops:
9
9
  Documentation:
10
10
  Enabled: false
11
11
 
12
+ Style/FrozenStringLiteralComment:
13
+ Enabled: false
14
+
12
15
  Style/Encoding:
13
16
  Enabled: false
14
17
 
@@ -21,6 +24,9 @@ Style/TrailingBlankLines:
21
24
  Style/RedundantReturn:
22
25
  Enabled: false
23
26
 
27
+ Style/SignalException:
28
+ Enabled: true
29
+
24
30
  Style/HashSyntax:
25
31
  EnforcedStyle: hash_rockets
26
32
 
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.0.0
5
5
  - 2.1.2
6
- - 2.2.0
6
+ - 2.2.2
7
7
  - 2.3.0
8
8
 
9
9
  before_install:
@@ -18,4 +18,12 @@ script:
18
18
 
19
19
  gemfile:
20
20
  - gemfiles/activesupport_3.gemfile
21
- - gemfiles/activesupport_4.gemfileset
21
+ - gemfiles/activesupport_4.gemfile
22
+ - gemfiles/activesupport_5.gemfile
23
+
24
+ matrix:
25
+ exclude:
26
+ - rvm: 2.0.0
27
+ gemfile: gemfiles/activesupport_5.gemfile
28
+ - rvm: 2.1.2
29
+ gemfile: gemfiles/activesupport_5.gemfile
data/Appraisals CHANGED
@@ -5,3 +5,7 @@ end
5
5
  appraise "activesupport-4" do
6
6
  gem "activesupport", "~> 4.0"
7
7
  end
8
+
9
+ appraise "activesupport-5" do
10
+ gem "activesupport", "~> 5.0"
11
+ end
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![LightService](resources/light-service.png)
1
+ ![LightService](https://raw.github.com/adomokos/light-service/master/resources/light-service.png)
2
2
 
3
3
  [![Gem Version](https://img.shields.io/gem/v/light-service.svg)](https://rubygems.org/gems/light-service)
4
4
  [![Build Status](https://secure.travis-ci.org/adomokos/light-service.png)](http://travis-ci.org/adomokos/light-service)
@@ -62,13 +62,13 @@ and executes them one-by-one. Then you need to create the actions which will onl
62
62
 
63
63
  This is how the organizer and actions interact with eachother:
64
64
 
65
- ![LightService](resources/organizer_and_actions.png)
65
+ ![LightService](https://raw.github.com/adomokos/light-service/master/resources/organizer_and_actions.png)
66
66
 
67
67
  ```ruby
68
68
  class CalculatesTax
69
69
  extend LightService::Organizer
70
70
 
71
- def self.for_order(order)
71
+ def self.call(order)
72
72
  with(:order => order).reduce(
73
73
  LooksUpTaxPercentageAction,
74
74
  CalculatesOrderTaxAction,
@@ -201,7 +201,7 @@ class SubmitsOrderAction
201
201
  end
202
202
  end
203
203
  ```
204
- ![LightService](resources/fail_actions.png)
204
+ ![LightService](https://raw.github.com/adomokos/light-service/master/resources/fail_actions.png)
205
205
 
206
206
  In the example above the organizer called 4 actions. The first 2 actions got executed successfully. The 3rd had a failure, that pushed the context into a failure state and the 4th action was skipped.
207
207
 
@@ -221,7 +221,7 @@ class ChecksOrderStatusAction
221
221
  end
222
222
  end
223
223
  ```
224
- ![LightService](resources/skip_actions.png)
224
+ ![LightService](https://raw.github.com/adomokos/light-service/master/resources/skip_actions.png)
225
225
 
226
226
  In the example above the organizer called 4 actions. The first 2 actions got executed successfully. The 3rd decided to skip the rest, the 4th action was not invoked. The context was successful.
227
227
 
@@ -251,7 +251,7 @@ end
251
251
  class CalculatesTax
252
252
  extend LightService::Organizer
253
253
 
254
- def self.for_order(order)
254
+ def self.call(order)
255
255
  with(:order => order).around_each(LogDuration).reduce(
256
256
  LooksUpTaxPercentageAction,
257
257
  CalculatesOrderTaxAction,
@@ -316,7 +316,7 @@ class FooAction
316
316
  end
317
317
  ```
318
318
 
319
- Take a look at [this spec](spec/action_expects_and_promises_spec.rb) to see the refactoring in action.
319
+ Take a look at [this spec](https://github.com/adomokos/light-service/blob/master/spec/action_expects_and_promises_spec.rb) to see the refactoring in action.
320
320
 
321
321
  ## Key Aliases
322
322
  The `aliases` macro sets up pairs of keys and aliases in an organizer. Actions can access the context using the aliases.
@@ -331,7 +331,7 @@ class AnOrganizer
331
331
 
332
332
  aliases my_key: :key_alias
333
333
 
334
- def self.for_order(order)
334
+ def self.call(order)
335
335
  with(:order => order).reduce(
336
336
  AnAction,
337
337
  AnotherAction,
@@ -492,7 +492,7 @@ Using the `rolled_back` macro is optional for the actions in the chain. You shou
492
492
 
493
493
  The actions are rolled back in reversed order from the point of failure starting with the action that triggered it.
494
494
 
495
- See [this](spec/acceptance/rollback_spec.rb) acceptance test to learn more about this functionality.
495
+ See [this](https://github.com/adomokos/light-service/blob/master/spec/acceptance/rollback_spec.rb) acceptance test to learn more about this functionality.
496
496
 
497
497
  ## Localizing Messages
498
498
  By default LightService provides a mechanism for easily translating your error or success messages via I18n. You can also provide your own custom localization adapter if your application's logic is more complex than what is shown here.
data/RELEASES.md CHANGED
@@ -1,5 +1,8 @@
1
1
  A brief list of new features and changes introduced with the specified version.
2
2
 
3
+ ### 0.7.0
4
+ * Organizers should have a public method [call](https://github.com/adomokos/light-service/pull/98) in preparation of orchestrators.
5
+
3
6
  ### 0.6.1
4
7
  * Introducing [around_each](https://github.com/adomokos/light-service/pull/79) for AOP style logging and code execution
5
8
  * Introducing [Rubocop](https://github.com/adomokos/light-service/commit/39aa7ea39f69a16c2df66b213fb6d638796e25f2) to the project, forcing consistant style
data/Rakefile CHANGED
@@ -3,3 +3,11 @@ require "bundler/gem_tasks"
3
3
 
4
4
  require "rubygems"
5
5
  require "bundler/setup"
6
+
7
+ require 'rspec/core/rake_task'
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task(:default).clear
13
+ task :default => [:spec, :rubocop]
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- light-service (0.6.0)
4
+ light-service (0.6.1)
5
5
  activesupport (>= 3.0)
6
6
 
7
7
  GEM
@@ -14,15 +14,22 @@ GEM
14
14
  bundler
15
15
  rake
16
16
  thor (>= 0.14.0)
17
- coderay (1.0.9)
17
+ ast (2.3.0)
18
+ coderay (1.1.1)
18
19
  diff-lcs (1.2.5)
20
+ docile (1.1.5)
19
21
  i18n (0.7.0)
22
+ json (2.0.2)
20
23
  method_source (0.8.2)
21
24
  multi_json (1.11.2)
22
- pry (0.9.12.2)
23
- coderay (~> 1.0.5)
24
- method_source (~> 0.8)
25
+ parser (2.3.1.2)
26
+ ast (~> 2.2)
27
+ powerpack (0.1.1)
28
+ pry (0.10.4)
29
+ coderay (~> 1.1.0)
30
+ method_source (~> 0.8.1)
25
31
  slop (~> 3.4)
32
+ rainbow (2.1.0)
26
33
  rake (10.4.2)
27
34
  rspec (3.3.0)
28
35
  rspec-core (~> 3.3.0)
@@ -33,19 +40,25 @@ GEM
33
40
  rspec-expectations (3.3.1)
34
41
  diff-lcs (>= 1.2.0, < 2.0)
35
42
  rspec-support (~> 3.3.0)
36
- rspec-its (1.2.0)
37
- rspec-core (>= 3.0.0)
38
- rspec-expectations (>= 3.0.0)
39
43
  rspec-mocks (3.3.2)
40
44
  diff-lcs (>= 1.2.0, < 2.0)
41
45
  rspec-support (~> 3.3.0)
42
46
  rspec-support (3.3.0)
43
- simplecov (0.7.1)
44
- multi_json (~> 1.0)
45
- simplecov-html (~> 0.7.1)
46
- simplecov-html (0.7.1)
47
+ rubocop (0.42.0)
48
+ parser (>= 2.3.1.1, < 3.0)
49
+ powerpack (~> 0.1)
50
+ rainbow (>= 1.99.1, < 3.0)
51
+ ruby-progressbar (~> 1.7)
52
+ unicode-display_width (~> 1.0, >= 1.0.1)
53
+ ruby-progressbar (1.8.1)
54
+ simplecov (0.12.0)
55
+ docile (~> 1.1.0)
56
+ json (>= 1.8, < 3)
57
+ simplecov-html (~> 0.10.0)
58
+ simplecov-html (0.10.0)
47
59
  slop (3.6.0)
48
60
  thor (0.19.1)
61
+ unicode-display_width (1.1.1)
49
62
 
50
63
  PLATFORMS
51
64
  ruby
@@ -54,10 +67,10 @@ DEPENDENCIES
54
67
  activesupport (~> 3.0)
55
68
  appraisal (~> 2.0)
56
69
  light-service!
57
- pry (= 0.9.12.2)
70
+ pry (~> 0.10)
58
71
  rspec (~> 3.0)
59
- rspec-its (~> 1.0)
60
- simplecov (~> 0.7.1)
72
+ rubocop (~> 0.36)
73
+ simplecov (~> 0.11)
61
74
 
62
75
  BUNDLED WITH
63
- 1.10.6
76
+ 1.12.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- light-service (0.6.0)
4
+ light-service (0.6.1)
5
5
  activesupport (>= 3.0)
6
6
 
7
7
  GEM
@@ -17,17 +17,22 @@ GEM
17
17
  bundler
18
18
  rake
19
19
  thor (>= 0.14.0)
20
- coderay (1.0.9)
20
+ ast (2.3.0)
21
+ coderay (1.1.1)
21
22
  diff-lcs (1.2.5)
23
+ docile (1.1.5)
22
24
  i18n (0.7.0)
23
25
  json (1.8.3)
24
26
  method_source (0.8.2)
25
27
  minitest (5.7.0)
26
- multi_json (1.11.2)
27
- pry (0.9.12.2)
28
- coderay (~> 1.0.5)
29
- method_source (~> 0.8)
28
+ parser (2.3.1.2)
29
+ ast (~> 2.2)
30
+ powerpack (0.1.1)
31
+ pry (0.10.4)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.8.1)
30
34
  slop (~> 3.4)
35
+ rainbow (2.1.0)
31
36
  rake (10.4.2)
32
37
  rspec (3.3.0)
33
38
  rspec-core (~> 3.3.0)
@@ -38,22 +43,28 @@ GEM
38
43
  rspec-expectations (3.3.1)
39
44
  diff-lcs (>= 1.2.0, < 2.0)
40
45
  rspec-support (~> 3.3.0)
41
- rspec-its (1.2.0)
42
- rspec-core (>= 3.0.0)
43
- rspec-expectations (>= 3.0.0)
44
46
  rspec-mocks (3.3.2)
45
47
  diff-lcs (>= 1.2.0, < 2.0)
46
48
  rspec-support (~> 3.3.0)
47
49
  rspec-support (3.3.0)
48
- simplecov (0.7.1)
49
- multi_json (~> 1.0)
50
- simplecov-html (~> 0.7.1)
51
- simplecov-html (0.7.1)
50
+ rubocop (0.42.0)
51
+ parser (>= 2.3.1.1, < 3.0)
52
+ powerpack (~> 0.1)
53
+ rainbow (>= 1.99.1, < 3.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (~> 1.0, >= 1.0.1)
56
+ ruby-progressbar (1.8.1)
57
+ simplecov (0.12.0)
58
+ docile (~> 1.1.0)
59
+ json (>= 1.8, < 3)
60
+ simplecov-html (~> 0.10.0)
61
+ simplecov-html (0.10.0)
52
62
  slop (3.6.0)
53
63
  thor (0.19.1)
54
64
  thread_safe (0.3.5)
55
65
  tzinfo (1.2.2)
56
66
  thread_safe (~> 0.1)
67
+ unicode-display_width (1.1.1)
57
68
 
58
69
  PLATFORMS
59
70
  ruby
@@ -62,10 +73,10 @@ DEPENDENCIES
62
73
  activesupport (~> 4.0)
63
74
  appraisal (~> 2.0)
64
75
  light-service!
65
- pry (= 0.9.12.2)
76
+ pry (~> 0.10)
66
77
  rspec (~> 3.0)
67
- rspec-its (~> 1.0)
68
- simplecov (~> 0.7.1)
78
+ rubocop (~> 0.36)
79
+ simplecov (~> 0.11)
69
80
 
70
81
  BUNDLED WITH
71
- 1.10.6
82
+ 1.12.5
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal", "~> 2.0"
6
+ gem "activesupport", "~> 5.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ light-service (0.6.1)
5
+ activesupport (>= 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.0.0.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ appraisal (2.1.0)
16
+ bundler
17
+ rake
18
+ thor (>= 0.14.0)
19
+ ast (2.3.0)
20
+ coderay (1.1.1)
21
+ concurrent-ruby (1.0.2)
22
+ diff-lcs (1.2.5)
23
+ docile (1.1.5)
24
+ i18n (0.7.0)
25
+ json (2.0.2)
26
+ method_source (0.8.2)
27
+ minitest (5.9.0)
28
+ parser (2.3.1.2)
29
+ ast (~> 2.2)
30
+ powerpack (0.1.1)
31
+ pry (0.10.4)
32
+ coderay (~> 1.1.0)
33
+ method_source (~> 0.8.1)
34
+ slop (~> 3.4)
35
+ rainbow (2.1.0)
36
+ rake (11.2.2)
37
+ rspec (3.5.0)
38
+ rspec-core (~> 3.5.0)
39
+ rspec-expectations (~> 3.5.0)
40
+ rspec-mocks (~> 3.5.0)
41
+ rspec-core (3.5.2)
42
+ rspec-support (~> 3.5.0)
43
+ rspec-expectations (3.5.0)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.5.0)
46
+ rspec-mocks (3.5.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.5.0)
49
+ rspec-support (3.5.0)
50
+ rubocop (0.42.0)
51
+ parser (>= 2.3.1.1, < 3.0)
52
+ powerpack (~> 0.1)
53
+ rainbow (>= 1.99.1, < 3.0)
54
+ ruby-progressbar (~> 1.7)
55
+ unicode-display_width (~> 1.0, >= 1.0.1)
56
+ ruby-progressbar (1.8.1)
57
+ simplecov (0.12.0)
58
+ docile (~> 1.1.0)
59
+ json (>= 1.8, < 3)
60
+ simplecov-html (~> 0.10.0)
61
+ simplecov-html (0.10.0)
62
+ slop (3.6.0)
63
+ thor (0.19.1)
64
+ thread_safe (0.3.5)
65
+ tzinfo (1.2.2)
66
+ thread_safe (~> 0.1)
67
+ unicode-display_width (1.1.1)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ activesupport (~> 5.0)
74
+ appraisal (~> 2.0)
75
+ light-service!
76
+ pry (~> 0.10)
77
+ rspec (~> 3.0)
78
+ rubocop (~> 0.36)
79
+ simplecov (~> 0.11)
80
+
81
+ BUNDLED WITH
82
+ 1.12.5
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module LightService
2
4
  module Action
3
5
  def self.extended(base_class)
@@ -13,13 +15,11 @@ module LightService
13
15
 
14
16
  module Macros
15
17
  def expects(*args)
16
- @_expected_keys ||= []
17
- @_expected_keys.concat(args)
18
+ expected_keys.concat(args)
18
19
  end
19
20
 
20
21
  def promises(*args)
21
- @_promised_keys ||= []
22
- @_promised_keys.concat(args)
22
+ promised_keys.concat(args)
23
23
  end
24
24
 
25
25
  def expected_keys
@@ -48,7 +48,7 @@ module LightService
48
48
 
49
49
  def rolled_back
50
50
  msg = "`rolled_back` macro can not be invoked again"
51
- fail msg if respond_to?(:rollback)
51
+ raise msg if respond_to?(:rollback)
52
52
 
53
53
  define_singleton_method :rollback do |context = {}|
54
54
  yield(context)
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module LightService
2
4
  module Outcomes
3
5
  SUCCESS = 0
@@ -22,7 +24,7 @@ module LightService
22
24
  def self.make(context = {})
23
25
  unless context.is_a?(Hash) || context.is_a?(LightService::Context)
24
26
  msg = 'Argument must be Hash or LightService::Context'
25
- fail ArgumentError, msg
27
+ raise ArgumentError, msg
26
28
  end
27
29
 
28
30
  context = new(context) unless context.is_a?(Context)
@@ -81,7 +83,7 @@ module LightService
81
83
 
82
84
  def fail_with_rollback!(message = nil, error_code = nil)
83
85
  fail!(message, error_code)
84
- fail(FailWithRollbackError)
86
+ raise FailWithRollbackError
85
87
  end
86
88
 
87
89
  def skip_all!(message = nil)
@@ -115,7 +117,8 @@ module LightService
115
117
  end
116
118
 
117
119
  def [](key)
118
- super(key) || super(aliases.key(key))
120
+ key = aliases.key(key) || key
121
+ return super(key)
119
122
  end
120
123
 
121
124
  def fetch(key, default_or_block = nil)
@@ -28,7 +28,7 @@ module LightService
28
28
  end
29
29
 
30
30
  def throw_error_predicate(_keys)
31
- fail NotImplementedError, 'Sorry, you have to override length'
31
+ raise NotImplementedError, 'Sorry, you have to override length'
32
32
  end
33
33
 
34
34
  def verify
@@ -36,7 +36,7 @@ module LightService
36
36
 
37
37
  if throw_error_predicate(keys)
38
38
  Configuration.logger.error error_message
39
- fail error_to_throw, error_message
39
+ raise error_to_throw, error_message
40
40
  end
41
41
 
42
42
  context
@@ -1,3 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
1
3
  module LightService
2
4
  module Organizer
3
5
  def self.extended(base_class)
@@ -9,13 +11,13 @@ module LightService
9
11
  warning_msg = "including LightService::Organizer is deprecated. " \
10
12
  "Please use `extend LightService::Organizer` instead"
11
13
  ActiveSupport::Deprecation.warn(warning_msg)
12
- base_class.extend ClassMethods
13
- base_class.extend Macros
14
+ extended(base_class)
14
15
  end
15
16
 
16
17
  # In case this module is included
17
18
  module ClassMethods
18
19
  def with(data = {})
20
+ VerifyCallMethodExists.call(self, caller.first)
19
21
  data[:_aliases] = @aliases if @aliases
20
22
  WithReducerFactory.make(self).with(data)
21
23
  end
@@ -23,6 +25,31 @@ module LightService
23
25
  def reduce(*actions)
24
26
  with({}).reduce(actions)
25
27
  end
28
+
29
+ # We need to make sure existing users will
30
+ # use `call` method name going forward.
31
+ # This should be removed eventually.
32
+ class VerifyCallMethodExists
33
+ def self.call(klass, first_caller = '')
34
+ invoker_method = caller_method(first_caller)
35
+ return if invoker_method == 'call'
36
+
37
+ call_method_exists = klass.methods.include?(:call)
38
+ return if call_method_exists
39
+
40
+ warning_msg = "The <#{klass.name}> class is an organizer, " \
41
+ "its entry method (the one that calls with & reduce) " \
42
+ "should be named `call`. " \
43
+ "Please use #{klass}.call going forward."
44
+ ActiveSupport::Deprecation.warn(warning_msg)
45
+ end
46
+
47
+ def self.caller_method(first_caller)
48
+ return nil unless first_caller =~ /`(.*)'/
49
+
50
+ Regexp.last_match[1]
51
+ end
52
+ end
26
53
  end
27
54
 
28
55
  module Macros
@@ -14,7 +14,7 @@ module LightService
14
14
  end
15
15
 
16
16
  def reduce(*actions)
17
- fail "No action(s) were provided" if actions.empty?
17
+ raise "No action(s) were provided" if actions.empty?
18
18
  actions.flatten!
19
19
 
20
20
  actions.reduce(context) do |current_context, action|
@@ -1,4 +1,3 @@
1
- # frozen_string_literal: true
2
1
  module LightService
3
- VERSION = "0.6.1".freeze
2
+ VERSION = "0.7.0".freeze
4
3
  end
@@ -3,7 +3,7 @@ require 'test_doubles'
3
3
 
4
4
  describe TestDoubles::AdditionOrganizer do
5
5
  it "Adds 1, 2 and 3 to the initial value of 1" do
6
- result = TestDoubles::AdditionOrganizer.add_numbers 1
6
+ result = TestDoubles::AdditionOrganizer.call(1)
7
7
  number = result.fetch(:product)
8
8
 
9
9
  expect(number).to eq(7)
@@ -19,7 +19,7 @@ describe "Executing arbitrary code around each action" do
19
19
  assert_before_action_execute_log
20
20
  assert_after_action_execute_log
21
21
 
22
- result = TestDoubles::AroundEachOrganizer.add(context)
22
+ result = TestDoubles::AroundEachOrganizer.call(context)
23
23
 
24
24
  expect(result.fetch(:number)).to eq(2)
25
25
  end
@@ -4,7 +4,7 @@ require "test_doubles"
4
4
  class TestsLocalizationAdapter
5
5
  extend LightService::Organizer
6
6
 
7
- def self.with_message(pass_or_fail, message_or_key, i18n_options = {})
7
+ def self.call(pass_or_fail, message_or_key, i18n_options = {})
8
8
  with(
9
9
  :pass_or_fail => pass_or_fail,
10
10
  :message_or_key => message_or_key,
@@ -27,18 +27,19 @@ class TestsLocalizationInvocationOptionsAction
27
27
  end
28
28
 
29
29
  def pass_with(message_or_key, i18n_options = {})
30
- TestsLocalizationAdapter.with_message(true, message_or_key, i18n_options)
30
+ TestsLocalizationAdapter.call(true, message_or_key, i18n_options)
31
31
  end
32
32
 
33
33
  def fail_with(message_or_key, i18n_options = {})
34
- TestsLocalizationAdapter.with_message(false, message_or_key, i18n_options)
34
+ TestsLocalizationAdapter.call(false, message_or_key, i18n_options)
35
35
  end
36
36
 
37
37
  describe "Localization Adapter" do
38
38
  before do
39
39
  I18n.backend.store_translations(
40
40
  :en,
41
- :tests_localization_invocation_options_action => {
41
+ :tests_localization_invocation_options_action =>
42
+ {
42
43
  :light_service => {
43
44
  :failures => {
44
45
  :some_failure_reason => "This has failed",
@@ -49,7 +50,8 @@ describe "Localization Adapter" do
49
50
  :success_with_interpolation => "Passed with %{reason}"
50
51
  }
51
52
  }
52
- })
53
+ }
54
+ )
53
55
  end
54
56
 
55
57
  describe "passing a simple string message" do
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'test_doubles'
3
+
4
+ describe "Organizer should invoke with/reduce from a call method" do
5
+ context "when the organizer does not have a `call` method" do
6
+ it "gives warning" do
7
+ expect(ActiveSupport::Deprecation)
8
+ .to receive(:warn)
9
+ .with(/^The <OrganizerWithoutCallMethod> class is an organizer/)
10
+
11
+ class OrganizerWithoutCallMethod
12
+ extend LightService::Organizer
13
+
14
+ def self.do_something
15
+ reduce([])
16
+ end
17
+ end
18
+
19
+ OrganizerWithoutCallMethod.do_something
20
+ end
21
+ end
22
+
23
+ context "when the organizer has the `call` method" do
24
+ it "does not issue a warning" do
25
+ expect(ActiveSupport::Deprecation)
26
+ .not_to receive(:warn)
27
+
28
+ class OrganizerWithCallMethod
29
+ extend LightService::Organizer
30
+
31
+ def self.call
32
+ reduce([])
33
+ end
34
+ end
35
+
36
+ OrganizerWithCallMethod.call
37
+ end
38
+ end
39
+ end
@@ -4,7 +4,7 @@ require 'test_doubles'
4
4
  class RollbackOrganizer
5
5
  extend LightService::Organizer
6
6
 
7
- def self.for(number)
7
+ def self.call(number)
8
8
  with(:number => number).reduce(
9
9
  AddsOneWithRollbackAction,
10
10
  TestDoubles::AddsTwoAction,
@@ -19,7 +19,7 @@ class AddsOneWithRollbackAction
19
19
  promises :number
20
20
 
21
21
  executed do |context|
22
- context.fail_with_rollback! if context.number == 0
22
+ context.fail_with_rollback! if context.number.zero?
23
23
 
24
24
  context.number += 1
25
25
  end
@@ -47,7 +47,7 @@ end
47
47
  class RollbackOrganizerWithNoRollback
48
48
  extend LightService::Organizer
49
49
 
50
- def self.for(number)
50
+ def self.call(number)
51
51
  with(:number => number).reduce(
52
52
  TestDoubles::AddsOneAction,
53
53
  TestDoubles::AddsTwoAction,
@@ -70,7 +70,7 @@ end
70
70
  class RollbackOrganizerWithMiddleRollback
71
71
  extend LightService::Organizer
72
72
 
73
- def self.for(number)
73
+ def self.call(number)
74
74
  with(:number => number).reduce(
75
75
  TestDoubles::AddsOneAction,
76
76
  AddsTwoActionWithRollback,
@@ -96,7 +96,7 @@ end
96
96
 
97
97
  describe "Rolling back actions when there is a failure" do
98
98
  it "Adds 1, 2, 3 to 1 and rolls back " do
99
- result = RollbackOrganizer.for 1
99
+ result = RollbackOrganizer.call 1
100
100
  number = result.fetch(:number)
101
101
 
102
102
  expect(result).to be_failure
@@ -105,7 +105,7 @@ describe "Rolling back actions when there is a failure" do
105
105
  end
106
106
 
107
107
  it "won't error out when actions don't define rollback" do
108
- result = RollbackOrganizerWithNoRollback.for 1
108
+ result = RollbackOrganizerWithNoRollback.call 1
109
109
  number = result.fetch(:number)
110
110
 
111
111
  expect(result).to be_failure
@@ -114,7 +114,7 @@ describe "Rolling back actions when there is a failure" do
114
114
  end
115
115
 
116
116
  it "rolls back properly when triggered with an action in the middle" do
117
- result = RollbackOrganizerWithMiddleRollback.for 1
117
+ result = RollbackOrganizerWithMiddleRollback.call 1
118
118
  number = result.fetch(:number)
119
119
 
120
120
  expect(result).to be_failure
@@ -123,7 +123,7 @@ describe "Rolling back actions when there is a failure" do
123
123
  end
124
124
 
125
125
  it "rolls back from the first action" do
126
- result = RollbackOrganizer.for 0
126
+ result = RollbackOrganizer.call 0
127
127
  number = result.fetch(:number)
128
128
 
129
129
  expect(result).to be_failure
data/spec/context_spec.rb CHANGED
@@ -157,14 +157,20 @@ describe LightService::Context do
157
157
  expect(context.outcome).to eq(::LightService::Outcomes::SUCCESS)
158
158
  end
159
159
 
160
+ it "can contain false values" do
161
+ context = LightService::Context.make(:foo => false)
162
+ expect(context[:foo]).to eq false
163
+ end
164
+
160
165
  context "when aliases are included via .make" do
161
166
  let(:context) do
162
167
  LightService::Context.make(
163
168
  :foo => "foobar",
169
+ :foo2 => false,
164
170
  :_aliases => aliases
165
171
  )
166
172
  end
167
- let(:aliases) { { :foo => :bar } }
173
+ let(:aliases) { { :foo => :bar, :foo2 => :bar2 } }
168
174
 
169
175
  it "contains the aliases" do
170
176
  expect(context.aliases).to eq(aliases)
@@ -175,5 +181,9 @@ describe LightService::Context do
175
181
  expect(context[:bar]).to eq context[:foo]
176
182
  expect(context.fetch(:bar)).to eq context[:foo]
177
183
  end
184
+
185
+ it "can contain false values" do
186
+ expect(context[:bar2]).to eq false
187
+ end
178
188
  end
179
189
  end
@@ -36,7 +36,7 @@ describe LightService::Organizer::WithReducer do
36
36
  it "reduces the rollback" do
37
37
  expect(action1).to receive(:execute).with(context).and_return(context)
38
38
  expect(action2).to receive(:execute).with(context) do
39
- fail LightService::FailWithRollbackError
39
+ raise LightService::FailWithRollbackError
40
40
  end
41
41
  expect(action1).to receive(:rollback).with(context).and_return(context)
42
42
  expect(action2).to receive(:rollback).with(context).and_return(context)
@@ -49,7 +49,7 @@ describe LightService::Organizer::WithReducer do
49
49
  it "reduces the rollback with an action without `rollback`" do
50
50
  expect(action1).to receive(:execute).with(context).and_return(context)
51
51
  expect(action2).to receive(:execute).with(context) do
52
- fail LightService::FailWithRollbackError
52
+ raise LightService::FailWithRollbackError
53
53
  end
54
54
  expect(action2).to receive(:rollback).with(context).and_return(context)
55
55
 
@@ -8,19 +8,20 @@ describe "organizer aliases macro" do
8
8
 
9
9
  aliases :promised_key => :expected_key
10
10
 
11
- def self.do_something(ctx = {})
11
+ def self.call(ctx = {})
12
12
  with(ctx).reduce(
13
13
  [
14
14
  TestDoubles::PromisesPromisedKeyAction,
15
15
  TestDoubles::ExpectsExpectedKeyAction
16
- ])
16
+ ]
17
+ )
17
18
  end
18
19
  end
19
20
  end
20
21
 
21
22
  context "when aliases is invoked" do
22
23
  it "makes aliases available to the actions" do
23
- result = organizer_with_alias.do_something
24
+ result = organizer_with_alias.call
24
25
  expect(result[:expected_key]).to eq(result[:promised_key])
25
26
  expect(result.expected_key).to eq(result[:promised_key])
26
27
  end
@@ -16,7 +16,7 @@ describe LightService::Organizer do
16
16
  end
17
17
 
18
18
  it "implicitly creates a Context" do
19
- result = TestDoubles::AnOrganizer.do_something(:user => user)
19
+ result = TestDoubles::AnOrganizer.call(:user => user)
20
20
  expect(result).to eq(ctx)
21
21
  end
22
22
  end
@@ -32,7 +32,7 @@ describe LightService::Organizer do
32
32
  end
33
33
 
34
34
  it "uses that Context without recreating it" do
35
- result = TestDoubles::AnOrganizer.do_something(ctx)
35
+ result = TestDoubles::AnOrganizer.call(ctx)
36
36
  expect(result).to eq(ctx)
37
37
  end
38
38
  end
@@ -64,7 +64,7 @@ describe LightService::Organizer do
64
64
  extend LightService::Organizer
65
65
  aliases :foo => :bar
66
66
 
67
- def self.do_stuff
67
+ def self.call
68
68
  with.reduce(TestDoubles::AnAction)
69
69
  end
70
70
  end
@@ -80,7 +80,7 @@ describe LightService::Organizer do
80
80
  .with(hash_including(:_aliases => { :foo => :bar }))
81
81
  .and_return(with_reducer)
82
82
 
83
- organizer.do_stuff
83
+ organizer.call
84
84
  end
85
85
  end
86
86
  end
@@ -26,7 +26,7 @@ describe CalculatesTax do
26
26
  .with(ctx)
27
27
  .and_return(ctx)
28
28
 
29
- result = CalculatesTax.for_order(order)
29
+ result = CalculatesTax.call(order)
30
30
 
31
31
  expect(result).to eq(ctx)
32
32
  end
@@ -1,7 +1,7 @@
1
1
  class CalculatesTax
2
2
  extend LightService::Organizer
3
3
 
4
- def self.for_order(order)
4
+ def self.call(order)
5
5
  with(:order => order).reduce(
6
6
  LooksUpTaxPercentageAction,
7
7
  CalculatesOrderTaxAction,
data/spec/test_doubles.rb CHANGED
@@ -19,7 +19,7 @@ module TestDoubles
19
19
 
20
20
  class AroundEachOrganizer
21
21
  extend LightService::Organizer
22
- def self.add(action_arguments)
22
+ def self.call(action_arguments)
23
23
  with(action_arguments)
24
24
  .around_each(AroundEachLoggerHandler)
25
25
  .reduce([AddsTwoActionWithFetch])
@@ -41,7 +41,7 @@ module TestDoubles
41
41
  class AnOrganizer
42
42
  extend LightService::Organizer
43
43
 
44
- def self.do_something(action_arguments)
44
+ def self.call(action_arguments)
45
45
  with(action_arguments).reduce([AnAction, AnotherAction])
46
46
  end
47
47
 
@@ -163,7 +163,7 @@ module TestDoubles
163
163
  class AdditionOrganizer
164
164
  extend LightService::Organizer
165
165
 
166
- def self.add_numbers(number)
166
+ def self.call(number)
167
167
  with(:number => number).reduce(
168
168
  AddsOneAction,
169
169
  AddsTwoAction,
@@ -248,7 +248,7 @@ module TestDoubles
248
248
  end
249
249
 
250
250
  def self.make_product
251
- fail "Fail"
251
+ raise "Fail"
252
252
  end
253
253
  private_class_method :make_product
254
254
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: light-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attila Domokos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2017-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: simplecov
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.36'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.36'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.10'
83
83
  description: A service skeleton with an emphasis on simplicity
@@ -87,11 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
92
- - .rubocop.yml
93
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
94
  - Appraisals
95
+ - CODE_OF_CONDUCT.md
95
96
  - Gemfile
96
97
  - LICENSE
97
98
  - README.md
@@ -101,6 +102,8 @@ files:
101
102
  - gemfiles/activesupport_3.gemfile.lock
102
103
  - gemfiles/activesupport_4.gemfile
103
104
  - gemfiles/activesupport_4.gemfile.lock
105
+ - gemfiles/activesupport_5.gemfile
106
+ - gemfiles/activesupport_5.gemfile.lock
104
107
  - lib/light-service.rb
105
108
  - lib/light-service/action.rb
106
109
  - lib/light-service/configuration.rb
@@ -123,6 +126,7 @@ files:
123
126
  - spec/acceptance/include_warning_spec.rb
124
127
  - spec/acceptance/log_from_organizer_spec.rb
125
128
  - spec/acceptance/message_localization_spec.rb
129
+ - spec/acceptance/not_having_call_method_warning_spec.rb
126
130
  - spec/acceptance/rollback_spec.rb
127
131
  - spec/action_expected_keys_spec.rb
128
132
  - spec/action_expects_and_promises_spec.rb
@@ -153,17 +157,17 @@ require_paths:
153
157
  - lib
154
158
  required_ruby_version: !ruby/object:Gem::Requirement
155
159
  requirements:
156
- - - '>='
160
+ - - ">="
157
161
  - !ruby/object:Gem::Version
158
162
  version: '0'
159
163
  required_rubygems_version: !ruby/object:Gem::Requirement
160
164
  requirements:
161
- - - '>='
165
+ - - ">="
162
166
  - !ruby/object:Gem::Version
163
167
  version: '0'
164
168
  requirements: []
165
169
  rubyforge_project:
166
- rubygems_version: 2.5.2
170
+ rubygems_version: 2.5.1
167
171
  signing_key:
168
172
  specification_version: 4
169
173
  summary: A service skeleton with an emphasis on simplicity
@@ -173,6 +177,7 @@ test_files:
173
177
  - spec/acceptance/include_warning_spec.rb
174
178
  - spec/acceptance/log_from_organizer_spec.rb
175
179
  - spec/acceptance/message_localization_spec.rb
180
+ - spec/acceptance/not_having_call_method_warning_spec.rb
176
181
  - spec/acceptance/rollback_spec.rb
177
182
  - spec/action_expected_keys_spec.rb
178
183
  - spec/action_expects_and_promises_spec.rb