cuprum 0.7.0 → 0.8.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/CHANGELOG.md +16 -0
- data/DEVELOPMENT.md +47 -41
- data/README.md +372 -56
- data/lib/cuprum/chaining.rb +128 -28
- data/lib/cuprum/command.rb +0 -3
- data/lib/cuprum/command_factory.rb +276 -0
- data/lib/cuprum/errors.rb +6 -0
- data/lib/cuprum/{not_implemented_error.rb → errors/process_not_implemented_error.rb} +7 -7
- data/lib/cuprum/operation.rb +3 -3
- data/lib/cuprum/processing.rb +10 -24
- data/lib/cuprum/result.rb +14 -2
- data/lib/cuprum/version.rb +1 -1
- metadata +19 -3
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'cuprum'
|
1
|
+
require 'cuprum/errors'
|
2
2
|
|
3
|
-
module Cuprum
|
3
|
+
module Cuprum::Errors
|
4
4
|
# Error class for calling a Command that was not given a definition block
|
5
5
|
# or have a #process method defined.
|
6
|
-
class
|
7
|
-
# Error message for a
|
6
|
+
class ProcessNotImplementedError < StandardError
|
7
|
+
# Error message for a ProcessNotImplementedError.
|
8
8
|
DEFAULT_MESSAGE = 'no implementation defined for command'.freeze
|
9
9
|
|
10
10
|
def initialize message = nil
|
11
11
|
super(message || DEFAULT_MESSAGE)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/cuprum/operation.rb
CHANGED
@@ -61,9 +61,9 @@ module Cuprum
|
|
61
61
|
# @yield If a block argument is given, it will be passed to the
|
62
62
|
# implementation.
|
63
63
|
#
|
64
|
-
# @raise [Cuprum::
|
65
|
-
# constructor or the #process method was overriden by a
|
66
|
-
# subclass.
|
64
|
+
# @raise [Cuprum::Errors::ProcessNotImplementedError] Unless a block was
|
65
|
+
# passed to the constructor or the #process method was overriden by a
|
66
|
+
# Command subclass.
|
67
67
|
#
|
68
68
|
# @see Cuprum::Command#call
|
69
69
|
def call *args, &block
|
data/lib/cuprum/processing.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'cuprum/
|
1
|
+
require 'cuprum/errors/process_not_implemented_error'
|
2
2
|
require 'cuprum/utils/result_not_empty_warning'
|
3
3
|
|
4
4
|
module Cuprum
|
@@ -94,12 +94,10 @@ module Cuprum
|
|
94
94
|
# @yield If a block argument is given, it will be passed to the
|
95
95
|
# implementation.
|
96
96
|
#
|
97
|
-
# @raise [Cuprum::
|
98
|
-
# overriden.
|
97
|
+
# @raise [Cuprum::Errors::ProcessNotImplementedError] Unless the #process
|
98
|
+
# method was overriden.
|
99
99
|
def call *args, &block
|
100
|
-
|
101
|
-
|
102
|
-
process_with_result(result, *args, &block)
|
100
|
+
process_with_result(build_result, *args, &block)
|
103
101
|
end # method call
|
104
102
|
|
105
103
|
private
|
@@ -108,20 +106,8 @@ module Cuprum
|
|
108
106
|
# is being called.
|
109
107
|
attr_reader :result
|
110
108
|
|
111
|
-
|
112
|
-
|
113
|
-
# Generates an empty errors object. When the command is called, the result
|
114
|
-
# will have its #errors property initialized to the value returned by
|
115
|
-
# #build_errors. By default, this is an array. If you want to use a custom
|
116
|
-
# errors object type, override this method in a subclass.
|
117
|
-
#
|
118
|
-
# @return [Array] An empty errors object.
|
119
|
-
def build_errors
|
120
|
-
[]
|
121
|
-
end # method build_errors
|
122
|
-
|
123
|
-
def build_result value, errors:
|
124
|
-
Cuprum::Result.new(value, :errors => errors)
|
109
|
+
def build_result value = nil, **options
|
110
|
+
Cuprum::Result.new(value, options)
|
125
111
|
end # method build_result
|
126
112
|
|
127
113
|
def merge_results result, other
|
@@ -153,13 +139,13 @@ module Cuprum
|
|
153
139
|
#
|
154
140
|
# @return [Object] the value of the result object to be returned by #call.
|
155
141
|
#
|
156
|
-
# @raise [Cuprum::
|
157
|
-
# constructor or the #process method was overriden by a
|
158
|
-
# subclass.
|
142
|
+
# @raise [Cuprum::Errors::ProcessNotImplementedError] Unless a block was
|
143
|
+
# passed to the constructor or the #process method was overriden by a
|
144
|
+
# Command subclass.
|
159
145
|
#
|
160
146
|
# @note This is a private method.
|
161
147
|
def process *_args
|
162
|
-
raise Cuprum::
|
148
|
+
raise Cuprum::Errors::ProcessNotImplementedError, nil, caller(1..-1)
|
163
149
|
end # method process
|
164
150
|
|
165
151
|
def process_with_result result, *args, &block
|
data/lib/cuprum/result.rb
CHANGED
@@ -6,9 +6,9 @@ module Cuprum
|
|
6
6
|
# @param value [Object] The value returned by calling the command.
|
7
7
|
# @param errors [Array] The errors (if any) generated when the command was
|
8
8
|
# called.
|
9
|
-
def initialize value = nil, errors:
|
9
|
+
def initialize value = nil, errors: nil
|
10
10
|
@value = value
|
11
|
-
@errors = errors
|
11
|
+
@errors = errors.nil? ? build_errors : errors
|
12
12
|
@status = nil
|
13
13
|
@halted = false
|
14
14
|
end # constructor
|
@@ -139,6 +139,18 @@ module Cuprum
|
|
139
139
|
|
140
140
|
private
|
141
141
|
|
142
|
+
# @!visibility public
|
143
|
+
#
|
144
|
+
# Generates an empty errors object. When the command is called, the result
|
145
|
+
# will have its #errors property initialized to the value returned by
|
146
|
+
# #build_errors. By default, this is an array. If you want to use a custom
|
147
|
+
# errors object type, override this method in a subclass.
|
148
|
+
#
|
149
|
+
# @return [Array] An empty errors object.
|
150
|
+
def build_errors
|
151
|
+
[]
|
152
|
+
end # method build_errors
|
153
|
+
|
142
154
|
def update_errors other_result
|
143
155
|
return if other_result.errors.empty?
|
144
156
|
|
data/lib/cuprum/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuprum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-
|
11
|
+
date: 2018-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sleeping_king_studios-tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,7 +115,9 @@ files:
|
|
101
115
|
- lib/cuprum/built_in/null_operation.rb
|
102
116
|
- lib/cuprum/chaining.rb
|
103
117
|
- lib/cuprum/command.rb
|
104
|
-
- lib/cuprum/
|
118
|
+
- lib/cuprum/command_factory.rb
|
119
|
+
- lib/cuprum/errors.rb
|
120
|
+
- lib/cuprum/errors/process_not_implemented_error.rb
|
105
121
|
- lib/cuprum/operation.rb
|
106
122
|
- lib/cuprum/processing.rb
|
107
123
|
- lib/cuprum/result.rb
|