cuprum 0.8.0 → 0.9.0.beta.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.
@@ -8,13 +8,13 @@ module Cuprum
8
8
  # Major version.
9
9
  MAJOR = 0
10
10
  # Minor version.
11
- MINOR = 8
11
+ MINOR = 9
12
12
  # Patch version.
13
13
  PATCH = 0
14
14
  # Prerelease version.
15
- PRERELEASE = nil
15
+ PRERELEASE = :beta
16
16
  # Build metadata.
17
- BUILD = nil
17
+ BUILD = 0
18
18
 
19
19
  class << self
20
20
  # Generates the gem version string from the Version constants.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuprum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0.beta.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-01 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sleeping_king_studios-tools
@@ -116,15 +116,18 @@ files:
116
116
  - lib/cuprum/chaining.rb
117
117
  - lib/cuprum/command.rb
118
118
  - lib/cuprum/command_factory.rb
119
+ - lib/cuprum/error.rb
119
120
  - lib/cuprum/errors.rb
120
- - lib/cuprum/errors/process_not_implemented_error.rb
121
+ - lib/cuprum/errors/command_not_implemented.rb
122
+ - lib/cuprum/errors/operation_not_called.rb
121
123
  - lib/cuprum/operation.rb
122
124
  - lib/cuprum/processing.rb
123
125
  - lib/cuprum/result.rb
124
- - lib/cuprum/result_helpers.rb
126
+ - lib/cuprum/rspec.rb
127
+ - lib/cuprum/rspec/be_a_result.rb
128
+ - lib/cuprum/rspec/be_a_result_matcher.rb
125
129
  - lib/cuprum/utils.rb
126
130
  - lib/cuprum/utils/instance_spy.rb
127
- - lib/cuprum/utils/result_not_empty_warning.rb
128
131
  - lib/cuprum/version.rb
129
132
  homepage: http://sleepingkingstudios.com
130
133
  licenses:
@@ -141,12 +144,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
144
  version: '0'
142
145
  required_rubygems_version: !ruby/object:Gem::Requirement
143
146
  requirements:
144
- - - ">="
147
+ - - ">"
145
148
  - !ruby/object:Gem::Version
146
- version: '0'
149
+ version: 1.3.1
147
150
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.6.13
151
+ rubygems_version: 3.0.3
150
152
  signing_key:
151
153
  specification_version: 4
152
154
  summary: An opinionated implementation of the Command pattern.
@@ -1,14 +0,0 @@
1
- require 'cuprum/errors'
2
-
3
- module Cuprum::Errors
4
- # Error class for calling a Command that was not given a definition block
5
- # or have a #process method defined.
6
- class ProcessNotImplementedError < StandardError
7
- # Error message for a ProcessNotImplementedError.
8
- DEFAULT_MESSAGE = 'no implementation defined for command'.freeze
9
-
10
- def initialize message = nil
11
- super(message || DEFAULT_MESSAGE)
12
- end
13
- end
14
- end
@@ -1,113 +0,0 @@
1
- require 'cuprum'
2
-
3
- module Cuprum
4
- # Helper methods that delegate result methods to the currently processed
5
- # result.
6
- #
7
- # @example
8
- # class LogCommand
9
- # include Cuprum::Processing
10
- # include Cuprum::ResultHelpers
11
- #
12
- # private
13
- #
14
- # def process log
15
- # case log[:level]
16
- # when 'fatal'
17
- # halt!
18
- #
19
- # 'error'
20
- # when 'error' && log[:message]
21
- # errors << message
22
- #
23
- # 'error'
24
- # when 'error'
25
- # failure!
26
- #
27
- # 'error'
28
- # else
29
- # 'ok'
30
- # end # case
31
- # end # method process
32
- # end # class
33
- #
34
- # result = LogCommand.new.call(:level => 'info')
35
- # result.success? #=> true
36
- #
37
- # string = 'something went wrong'
38
- # result = LogCommand.new.call(:level => 'error', :message => string)
39
- # result.success? #=> false
40
- # result.errors #=> ['something went wrong']
41
- #
42
- # result = LogCommand.new.call(:level => 'error')
43
- # result.success? #=> false
44
- # result.errors #=> []
45
- #
46
- # result = LogCommand.new.call(:level => 'fatal')
47
- # result.halted? #=> true
48
- #
49
- # @see Cuprum::Command
50
- module ResultHelpers
51
- private
52
-
53
- # @!visibility public
54
- #
55
- # Provides a reference to the current result's errors object. Messages or
56
- # error objects added to this will be included in the #errors method of the
57
- # returned result object.
58
- #
59
- # @return [Array, Object] The errors object.
60
- #
61
- # @see Cuprum::Result#errors.
62
- #
63
- # @note This is a private method, and only available when executing the
64
- # command implementation as defined in the constructor block or the
65
- # #process method.
66
- def errors
67
- result&.errors
68
- end # method errors
69
-
70
- # @!visibility public
71
- #
72
- # Marks the current result as failed. Calling #failure? on the returned
73
- # result object will evaluate to true, whether or not the result has any
74
- # errors.
75
- #
76
- # @see Cuprum::Result#failure!.
77
- #
78
- # @note This is a private method, and only available when executing the
79
- # command implementation as defined in the constructor block or the
80
- # #process method.
81
- def failure!
82
- result&.failure!
83
- end # method failure!
84
-
85
- # @!visibility public
86
- #
87
- # Marks the current result as halted.
88
- #
89
- # @see Cuprum::Result#halt!.
90
- #
91
- # @note This is a private method, and only available when executing the
92
- # command implementation as defined in the constructor block or the
93
- # #process method.
94
- def halt!
95
- result&.halt!
96
- end # method halt!
97
-
98
- # @!visibility public
99
- #
100
- # Marks the current result as passing. Calling #success? on the returned
101
- # result object will evaluate to true, whether or not the result has any
102
- # errors.
103
- #
104
- # @see Cuprum::Result#success!.
105
- #
106
- # @note This is a private method, and only available when executing the
107
- # command implementation as defined in the constructor block or the
108
- # #process method.
109
- def success!
110
- result&.success!
111
- end # method success!
112
- end # module
113
- end # module
@@ -1,72 +0,0 @@
1
- require 'cuprum/utils'
2
-
3
- module Cuprum::Utils
4
- # Helper class for building a warning message when a command returns a result,
5
- # but the command's current result already has errors, a set status, or is
6
- # halted.
7
- class ResultNotEmptyWarning
8
- MESSAGE = '#process returned a result, but '.freeze
9
- private_constant :MESSAGE
10
-
11
- # @param result [Cuprum::Result] The result for which to generate the
12
- # warning message.
13
- def initialize result
14
- @result = result
15
- end # constructor
16
-
17
- # @return [String] The warning message for the given result.
18
- def message
19
- return ''.freeze if warnings.empty?
20
-
21
- MESSAGE + humanize_list(warnings).freeze
22
- end # method message
23
-
24
- # @return [Boolean] True if a warning is generated, otherwise false.
25
- def warning?
26
- !warnings.empty?
27
- end # method warning?
28
-
29
- private
30
-
31
- attr_reader :result
32
-
33
- def errors_not_empty_warning
34
- return nil if result.errors.empty?
35
-
36
- "there were already errors #{@result.errors.inspect}".freeze
37
- end # method errors_not_empty_warning
38
-
39
- def halted_warning
40
- return nil unless result.halted?
41
-
42
- 'the command was halted'.freeze
43
- end # method halted_warning
44
-
45
- def humanize_list list, empty_value: ''
46
- return empty_value if list.size.zero?
47
-
48
- return list.first.to_s if list.size == 1
49
-
50
- return "#{list.first} and #{list.last}" if list.size == 2
51
-
52
- "#{list[0...-1].join ', '}, and #{list.last}"
53
- end # method humanize_list
54
-
55
- def status_set_warning
56
- status = result.send(:status)
57
-
58
- return nil if status.nil?
59
-
60
- "the status was set to #{status.inspect}".freeze
61
- end # method status_set_warning
62
-
63
- def warnings
64
- @warnings ||=
65
- [
66
- errors_not_empty_warning,
67
- status_set_warning,
68
- halted_warning
69
- ].compact
70
- end # method warnings
71
- end # class
72
- end # module