adama 0.1.4 → 0.1.5

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: 231eccdac40bdcb313b25f45d9469321fcb38175
4
- data.tar.gz: 12d424db073534825bbfc568a31a8f197231e42b
3
+ metadata.gz: d32465d56c5a8f938f26e1732fb75a786e22940d
4
+ data.tar.gz: fa589325c1a750016e692f0b73452b12f0b12250
5
5
  SHA512:
6
- metadata.gz: a29a64eb30a328191db5b99f1448fb6b92a290259380e6769bfe7a7adf49129cc8ee9a5ace4ba6f9ddd29c941fec9b27defef6170b5cdf3ed4c014b4bb7d66f4
7
- data.tar.gz: '02790d2adefc53c5cfcf2bd7eaf1e3dfec95a680b84cd0a865352e3e69a85e5bf1f6f92c08232605e9aff350b78d32b78b496fc8ced0b5ec0444208073fa43e1'
6
+ metadata.gz: 8c670d242b889c5ddc751e5fe9e7827401587d92c2fc50a01b3d3ef86f19b7af38aaae7c6795658bec8a051bdd45c086f3f5a7e02e3b8e5e67cbcf0ac74c0c01
7
+ data.tar.gz: 39cf0f7723a3005112c68ccb4a0ffc2b106d8a2448a426cf03f853ee002926b11623b878eab75ff3fead81a9b1c88b115d6adf469557a41c2392c2f6b91bb894
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Commander Adama
2
2
 
3
+ ![Adama](https://raw.githubusercontent.com/wiki/bugcrowd/adama/images/adama.jpg)
4
+
3
5
  Adama is a bare bones command pattern library inspired by Collective Idea's [Interactor](https://github.com/collectiveidea/interactor) gem.
4
6
 
5
7
  Commands are small classes that represent individual units of work. Each command is executed by a client "calling" it. An invoker is a class responsible for the execution of one or more commands.
@@ -86,6 +88,26 @@ Now, when you run `RebuildHumanRace.call(captain: :apollo, president: :laura)` i
86
88
 
87
89
  If there is an error in any of those commands, the invoker will call `FindEarth.rollback`, then `DestroyCylons.rollback`, then `GetArrowOfApollo.rollback` leaving everything just as it was in the beginning.
88
90
 
91
+ #### Instance Invoker List
92
+
93
+ Typically your Invoker class takes responsibility for an immutable set of actions, however sometimes it's handy to be able to adjust the invoked commands on the fly while keeping the error handling and rollback functionality of the invoker.
94
+
95
+ e.g.
96
+
97
+ ```ruby
98
+ class FightCylons
99
+ include Adama::Invoker
100
+ end
101
+
102
+ attack1 = Invoker.new(captain: :apollo, lieutenant: :starbuck).invoke(Advance, Strafe, Fire)
103
+ attack2 = Invoker.new(captain: :apollo, lieutenant: :starbuck).invoke(Advance, Fire)
104
+
105
+ attack1.run
106
+ attack2.run
107
+ ```
108
+
109
+ It's important to see that we're using the `#run` instance method on the Invoker instance (as the `.call` class method would). This ensures we execute the invoker in the error / rollback handler. Calling the `#call` instance method directly would simply execute each command, without any Invoker level error handling.
110
+
89
111
  ### Errors
90
112
 
91
113
  `Adama::Command#call` or `Adama::Invoker#call` will *always* raise an error of type `Adama::Errors::BaseError`.
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.14"
33
+ spec.add_development_dependency "bundler", "~> 2.0"
34
34
  spec.add_development_dependency "rake", "~> 10.0"
35
35
  spec.add_development_dependency "rspec", "~> 3.0"
36
36
  spec.add_development_dependency "pry"
@@ -36,13 +36,12 @@ module Adama
36
36
  # Internal instance method. Called by both the call class method, and by
37
37
  # the call method in the invoker. If it fails it raises a CommandError.
38
38
  def run
39
- command_caller = caller
40
- call
39
+ tap(&:call)
41
40
  rescue => error
42
41
  raise Errors::CommandError.new(
43
42
  error: error,
44
43
  command: self,
45
- backtrace: error.backtrace + ['Adama Command backtrace:'] + command_caller
44
+ backtrace: error.backtrace
46
45
  )
47
46
  end
48
47
 
@@ -22,7 +22,7 @@ module Adama
22
22
  include Command
23
23
 
24
24
  # Our new class methods enable us to set the command list
25
- extend ClassMethods
25
+ extend InvokeMethods
26
26
 
27
27
  # We override the Command class instance methods:
28
28
  #
@@ -30,11 +30,12 @@ module Adama
30
30
  # call
31
31
  # rollback
32
32
  include InstanceMethods
33
+ include InvokeMethods
33
34
  end
34
35
  end
35
36
 
36
37
  # Our new class methods enable us to set the command list
37
- module ClassMethods
38
+ module InvokeMethods
38
39
 
39
40
  # Public class method. Call invoke in your class definition to
40
41
  # specify which commands will be executed.
@@ -49,6 +50,10 @@ module Adama
49
50
  # )
50
51
  # end
51
52
  def invoke(*command_list)
53
+ if is_a?(Invoker) && self.class.commands.any?
54
+ raise(StandardError, 'Can\'t call invoke on an Invoker instance \
55
+ with a class invocation list.')
56
+ end
52
57
  @commands = command_list.flatten
53
58
  end
54
59
 
@@ -69,15 +74,14 @@ module Adama
69
74
  # invoker "call" instance method, we won't have access to error's
70
75
  # command so need to test for it's existence.
71
76
  def run
72
- command_caller = caller
73
- call
77
+ tap(&:call)
74
78
  rescue => error
75
79
  rollback
76
80
  raise Errors::InvokerError.new(
77
81
  error: error,
78
82
  command: error.respond_to?(:command) ? error.command : nil,
79
83
  invoker: self,
80
- backtrace: error.backtrace + ['Adama Invoker backtrace:'] + command_caller
84
+ backtrace: error.backtrace
81
85
  )
82
86
  end
83
87
 
@@ -103,7 +107,8 @@ module Adama
103
107
  # Iterate over the commands array, instantiate each command, run it,
104
108
  # and add it to the called list.
105
109
  def call
106
- self.class.commands.each do |command_klass|
110
+ commands = self.commands.any? ? self.commands : self.class.commands
111
+ commands.each do |command_klass|
107
112
  command = command_klass.new(kwargs)
108
113
  command.run
109
114
  _called << command
@@ -1,3 +1,3 @@
1
1
  module Adama
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adama
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - dradford
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2019-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.14'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.14'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement