commande 0.3.1 → 0.4.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
- SHA1:
3
- metadata.gz: d25e8ec7120ae92efec0d9213a85eb7406ba2cae
4
- data.tar.gz: 511b45c1ca6eb7d0b9f45a2322cc1c8e41f74e73
2
+ SHA256:
3
+ metadata.gz: 5334f1b703da19aebef8ef78454df5c22b1579200e4c6081849f1838c9590e09
4
+ data.tar.gz: 19e06efbfed90cf386054ac5c012f023e21f50f6ed770e88cabfb06544798195
5
5
  SHA512:
6
- metadata.gz: 5866e974388a65b94f57d4b053db322734f68090e71c438b6f47ffd20440625ceb9e205cd2a8628f94c6424f5b61b58469d35697d842b75a869be9e49f98aa07
7
- data.tar.gz: 602a9ffdd2b80d1c18cc3cef9702ce6bea0e230928c421151389bfaadd7aca264214cf6d75db2dc4dca4be658d0d33ddfd49f6e2d9680b4fdd8e7903386ce3a8
6
+ metadata.gz: '0392aa643a831494eb0ff6cfc1dbc9bd07b282a9a6d0394ee4d1d0a6c1d7eaa430b517a4baac6424f885ab7ed17da93525c6acef75e2c2ba6af14b64dbad822a'
7
+ data.tar.gz: 356fe5f2f6d97beecd770f11dfe7ba3cad4f4f4705786c1f4fb9a349cab2ec3492ac855b11ae09a82c0e7d1dedc42193a14fad5a9e1d58ebf72e1ce8785ed1fa
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+ - Add `Chain` for command chaining
5
+
3
6
  ## 0.3.1
4
7
  - Alias `output` as `outputs`
5
8
 
data/README.md CHANGED
@@ -78,6 +78,61 @@ result.successful? # => false
78
78
  result.fetched # => nil
79
79
  ```
80
80
 
81
+ ### Chaining
82
+
83
+ If you opt-in to chaining `require 'commande/chain'`, you can create a call chain that chains multiple `Commande`. The
84
+ only limitation is that you can _only_ use named arguments. This is to ensure breakage on unexpected output, name
85
+ mismatches and collisions.
86
+
87
+ ```ruby
88
+ require 'command'
89
+ require 'command/chain'
90
+
91
+ class StartCommand
92
+ include Commande
93
+
94
+ output :foo, :baz
95
+
96
+ def valid?(test:)
97
+ error! 'test must at least be 3' if test < 3
98
+
99
+ true
100
+ end
101
+
102
+ def call(test:)
103
+ self.foo = 'foo' * test
104
+ self.not_an_output = 'not_an_output'
105
+ end
106
+
107
+ private
108
+
109
+ attr_accessor :foo, :baz, :not_an_output
110
+ end
111
+
112
+ class SecondCommand
113
+ include Commande
114
+
115
+ output :result
116
+
117
+ def call(foo:, **_opts)
118
+ self.result = foo
119
+ end
120
+
121
+ private
122
+
123
+ attr_accessor :result
124
+ end
125
+
126
+ chained = Chain.new(StartCommand, SecondCommand).call(test: 3)
127
+ # => result is successful, and output matches `SecondCommand`
128
+ chained.chain_result.result
129
+ # => 'foofoofoo'
130
+
131
+ boomed = Chain.new(StartCommand, SecondCommand).call(test: 2)
132
+ # => boomed has failed, and output matches nil
133
+ boomed.error
134
+ # => 'test must at least be 3'
135
+ ```
81
136
  ## Testing
82
137
 
83
138
  There are some `Minitest` assertions included in this library.
data/commande.gemspec CHANGED
@@ -1,44 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'commande/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'commande'
9
- spec.version = Commande::VERSION
10
- spec.authors = ['Derk-Jan Karrenbeld']
11
- spec.email = ['derk-jan+github@karrenbeld.info']
12
-
13
- spec.summary = 'Allows for Command pattern style POROs'
14
- spec.license = 'MIT'
15
-
16
- spec.metadata = {
17
- 'bug_tracker_uri' => 'https://github.com/SleeplessByte/command/issues',
18
- 'changelog_uri' => 'https://github.com/SleeplessByte/command/CHANGELOG.md',
19
- 'homepage_uri' => 'https://github.com/SleeplessByte/command',
20
- 'source_code_uri' => 'https://github.com/SleeplessByte/command'
21
- }
22
-
23
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
- # to allow pushing to a single host or delete this section to allow pushing to any host.
25
- if spec.respond_to?(:metadata)
26
- # spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
27
- else
28
- raise 'RubyGems 2.0 or newer is required to protect against ' \
29
- 'public gem pushes.'
30
- end
31
-
32
- # Specify which files should be added to the gem when it is released.
33
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
- f.match(%r{^(test|spec|features)/})
36
- end
37
- spec.bindir = 'exe'
38
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
- spec.require_paths = ['lib']
40
-
41
- spec.add_development_dependency 'bundler', '~> 1.16'
42
- spec.add_development_dependency 'minitest', '~> 5.0'
43
- spec.add_development_dependency 'rake', '~> 10.0'
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'commande/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'commande'
9
+ spec.version = Commande::VERSION
10
+ spec.authors = ['Derk-Jan Karrenbeld']
11
+ spec.email = ['derk-jan+github@karrenbeld.info']
12
+
13
+ spec.summary = 'Allows for Command pattern style POROs'
14
+ spec.license = 'MIT'
15
+
16
+ spec.metadata = {
17
+ 'bug_tracker_uri' => 'https://github.com/SleeplessByte/command/issues',
18
+ 'changelog_uri' => 'https://github.com/SleeplessByte/command/CHANGELOG.md',
19
+ 'homepage_uri' => 'https://github.com/SleeplessByte/command',
20
+ 'source_code_uri' => 'https://github.com/SleeplessByte/command'
21
+ }
22
+
23
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
24
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
25
+ if spec.respond_to?(:metadata)
26
+ # spec.metadata['allowed_push_host'] = 'https://gems.sleeplessbyte.technology'
27
+ else
28
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
29
+ 'public gem pushes.'
30
+ end
31
+
32
+ # Specify which files should be added to the gem when it is released.
33
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
34
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
35
+ f.match(%r{^(test|spec|features)/})
36
+ end
37
+ spec.bindir = 'exe'
38
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
39
+ spec.require_paths = ['lib']
40
+
41
+ spec.add_development_dependency 'bundler', '~> 1.16'
42
+ spec.add_development_dependency 'minitest', '~> 5.0'
43
+ spec.add_development_dependency 'rake', '~> 12.3'
44
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'commande/chain'
@@ -1,5 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'command/minitest/assertions/assert_successful'
4
- require 'command/minitest/assertions/assert_valid'
5
- require 'command/minitest/assertions/assert_with_error'
3
+ require 'commande/minitest/'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Commande
4
+ class Chain
5
+ include Commande
6
+
7
+ output :chain_result
8
+
9
+ def initialize(*commands)
10
+ self.commands = commands
11
+ end
12
+
13
+ def chain(*commands)
14
+ new(*self.commands, *commands)
15
+ end
16
+
17
+ def valid(**_args)
18
+ error! 'needs at least one command' if commands.empty?
19
+
20
+ true
21
+ end
22
+
23
+ def call(**args)
24
+ self.chain_result = commands.inject(InitialCommandResult.new(args)) do |last_result, current_command|
25
+ current_result = current_command.call(**last_result.payload.dup)
26
+
27
+ transfer_logs current_result
28
+ transfer_errors current_result
29
+
30
+ fail! unless transfer_success? current_result
31
+ current_result
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ attr_accessor :commands, :chain_result
38
+
39
+ class InitialCommandResult
40
+ def initialize(**args)
41
+ self.payload = args
42
+ end
43
+
44
+ attr_reader :payload
45
+
46
+ private
47
+
48
+ attr_writer :payload
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commande
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.0'
5
5
  end
data/lib/commande.rb CHANGED
@@ -360,7 +360,7 @@ module Commande
360
360
  source.valid? && source.persisted?
361
361
  end
362
362
 
363
- def transfer_errors(source, header:)
363
+ def transfer_errors(source, header: nil)
364
364
  errors = source.errors
365
365
  errors = source.errors.full_messages if errors.respond_to?(:full_messages)
366
366
  Array(errors).each do |e|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commande
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-24 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.3'
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
- version: '10.0'
54
+ version: '12.3'
55
55
  description:
56
56
  email:
57
57
  - derk-jan+github@karrenbeld.info
@@ -72,11 +72,13 @@ files:
72
72
  - bin/setup
73
73
  - commande.gemspec
74
74
  - lib/command.rb
75
+ - lib/command/chain.rb
75
76
  - lib/command/minitest.rb
76
77
  - lib/command/minitest/assertions/assert_successful.rb
77
78
  - lib/command/minitest/assertions/assert_valid.rb
78
79
  - lib/command/minitest/assertions/assert_with_error.rb
79
80
  - lib/commande.rb
81
+ - lib/commande/chain.rb
80
82
  - lib/commande/minitest.rb
81
83
  - lib/commande/minitest/assertions/assert_successful.rb
82
84
  - lib/commande/minitest/assertions/assert_valid.rb
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
108
  version: '0'
107
109
  requirements: []
108
110
  rubyforge_project:
109
- rubygems_version: 2.6.14.1
111
+ rubygems_version: 2.7.8
110
112
  signing_key:
111
113
  specification_version: 4
112
114
  summary: Allows for Command pattern style POROs