composed_commands 1.0.1 → 1.1.0
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/README.md +21 -1
- data/lib/composed_commands.rb +1 -0
- data/lib/composed_commands/command_factory.rb +13 -0
- data/lib/composed_commands/composed_command.rb +10 -2
- data/lib/composed_commands/version.rb +1 -1
- data/spec/compound_commands/{compound_command_attributes_spec.rb → composed_command_attributes_spec.rb} +0 -0
- data/spec/compound_commands/{compound_command_spec.rb → composed_command_spec.rb} +14 -5
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d209b58f7f8bb590af4b58a10dad9726850b1ab1
|
4
|
+
data.tar.gz: d8584a3b2eb4c06c6371f1c5747df59adb4d4e2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77dd4802682c46749504b8b09fb3de1e051ba982b483271229b95765476c6ceb0f6becb27de4b4410911502e607574cee4c27b2b99d86016f647b88d4422a240
|
7
|
+
data.tar.gz: 4db9f234c3c57a93911306079dc290819d251e43bb194a8f47f29e2a12ea820287f59aaf97c4e63886e44673a81d990d1d708406636b9ecd63f1ebf7347f5559
|
data/README.md
CHANGED
@@ -175,7 +175,27 @@ class SomeComposedCommand < ComposedCommands::ComposedCommand
|
|
175
175
|
end
|
176
176
|
```
|
177
177
|
|
178
|
-
|
178
|
+
You can configure part of Composed Command at runtime using `before_execute` callback':
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
class AbilityChecker < ComposedCommands::ComposedCommand
|
182
|
+
attribute :user, User, require: true
|
183
|
+
|
184
|
+
use Presence
|
185
|
+
use RegisteredAt, after: '2010-10-10
|
186
|
+
use Admin
|
187
|
+
# ...
|
188
|
+
|
189
|
+
def before_execute(command)
|
190
|
+
command.user = user
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
ability = AbilityChecker.new(user: current_user)
|
195
|
+
ability.perform(post)
|
196
|
+
```
|
197
|
+
|
198
|
+
This gem based on [Composable Operations](https://github.com/t6d/composable_operations) written by Konstantin Tennhard
|
179
199
|
|
180
200
|
## Contributing
|
181
201
|
|
data/lib/composed_commands.rb
CHANGED
@@ -13,12 +13,20 @@ module ComposedCommands
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.use(klass, options = {})
|
16
|
-
(@commands ||= []).push(
|
16
|
+
(@commands ||= []).push(ComposedCommands::CommandFactory.new(klass, options))
|
17
|
+
end
|
18
|
+
|
19
|
+
def commands
|
20
|
+
self.class.commands.map do |command_factory|
|
21
|
+
command = command_factory.create
|
22
|
+
before_execute(command) if respond_to? :before_execute
|
23
|
+
command
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
protected
|
20
28
|
def execute(*args)
|
21
|
-
|
29
|
+
commands.inject(args) do |data, command|
|
22
30
|
command.perform(*Array(data))
|
23
31
|
|
24
32
|
if command.halted?
|
File without changes
|
@@ -4,6 +4,15 @@ RSpec.describe ComposedCommands::ComposedCommand do
|
|
4
4
|
let(:input) { 'chunky bacon' }
|
5
5
|
|
6
6
|
context '#perfrorm' do
|
7
|
+
it 'run factory creation callback' do
|
8
|
+
command = ChunkyBaconCapitalizer.new
|
9
|
+
def command.before_execute(command)
|
10
|
+
end
|
11
|
+
expect(command).to receive(:before_execute).twice
|
12
|
+
|
13
|
+
command.perform(input)
|
14
|
+
end
|
15
|
+
|
7
16
|
it 'performs successfully' do
|
8
17
|
command = ChunkyBaconCapitalizer.new
|
9
18
|
command.perform(input)
|
@@ -43,16 +52,16 @@ RSpec.describe ComposedCommands::ComposedCommand do
|
|
43
52
|
context '.use' do
|
44
53
|
subject(:command) { ChunkyBaconCapitalizer }
|
45
54
|
it { expect(command.commands.size).to eq 2 }
|
46
|
-
it { expect(command.commands.first).to
|
47
|
-
it { expect(command.commands.last).to
|
55
|
+
it { expect(command.commands.first.command).to eq StringGenerator }
|
56
|
+
it { expect(command.commands.last.command).to eq StringCapitalizer }
|
48
57
|
|
49
58
|
context 'inherited compound commands' do
|
50
59
|
subject(:child_command) { ChunkyBaconCapitalizerWithMuliplication }
|
51
60
|
|
52
61
|
it { expect(child_command.commands.size).to eq 3 }
|
53
|
-
it { expect(child_command.commands[0]).to
|
54
|
-
it { expect(child_command.commands[1]).to
|
55
|
-
it { expect(child_command.commands[2]).to
|
62
|
+
it { expect(child_command.commands[0].command).to eq StringGenerator }
|
63
|
+
it { expect(child_command.commands[1].command).to eq StringCapitalizer }
|
64
|
+
it { expect(child_command.commands[2].command).to eq StringMultiplier }
|
56
65
|
end
|
57
66
|
end
|
58
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composed_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tema Bolshakov
|
@@ -112,12 +112,13 @@ files:
|
|
112
112
|
- lib/composed_commands/command.rb
|
113
113
|
- lib/composed_commands/command/execution.rb
|
114
114
|
- lib/composed_commands/command/state.rb
|
115
|
+
- lib/composed_commands/command_factory.rb
|
115
116
|
- lib/composed_commands/composed_command.rb
|
116
117
|
- lib/composed_commands/version.rb
|
117
118
|
- spec/compound_commands/command_attributes_spec.rb
|
118
119
|
- spec/compound_commands/command_spec.rb
|
119
|
-
- spec/compound_commands/
|
120
|
-
- spec/compound_commands/
|
120
|
+
- spec/compound_commands/composed_command_attributes_spec.rb
|
121
|
+
- spec/compound_commands/composed_command_spec.rb
|
121
122
|
- spec/fixtures/commans.rb
|
122
123
|
- spec/spec_helper.rb
|
123
124
|
homepage: ''
|
@@ -147,7 +148,7 @@ summary: Tool for creating commands and commands chains.
|
|
147
148
|
test_files:
|
148
149
|
- spec/compound_commands/command_attributes_spec.rb
|
149
150
|
- spec/compound_commands/command_spec.rb
|
150
|
-
- spec/compound_commands/
|
151
|
-
- spec/compound_commands/
|
151
|
+
- spec/compound_commands/composed_command_attributes_spec.rb
|
152
|
+
- spec/compound_commands/composed_command_spec.rb
|
152
153
|
- spec/fixtures/commans.rb
|
153
154
|
- spec/spec_helper.rb
|