gl_command 1.1.4 → 1.3.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 +18 -0
- data/lib/gl_command/callable.rb +2 -2
- data/lib/gl_command/chainable.rb +1 -1
- data/lib/gl_command/context.rb +1 -5
- data/lib/gl_command/context_inspect.rb +40 -21
- data/lib/gl_command/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d64529ae90558047a1a67fb4641fcbc6807f4bac0ef8b503945d2981dac33f80
|
4
|
+
data.tar.gz: 541c75d629f1ba4971ab7d6fd37ac4a1fdfee2f19cb6256477d4857408fb64ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7767272a19c79ed50bc21bcd5a94a04f8f16c26e509bdfc3b86937e8204dabf2d053ea2fc85919acc56de3a770fd35ff88490b2d101fdcf6e6a89a714c55176f
|
7
|
+
data.tar.gz: f4fd2347bedf5ccbd94c09e230bf760d16d0ec1f19a4ecada73416d7a4b0da52a7f79759f074c4a38f98cd783ce45a07dd84c46dd1f13b87685cfdec8d0e9c9e
|
data/README.md
CHANGED
@@ -215,6 +215,24 @@ end
|
|
215
215
|
```
|
216
216
|
|
217
217
|
|
218
|
+
## Publishing the gem to Rubygems
|
219
|
+
|
220
|
+
1. As per our code agreements, all code changes to this gem are required to be made via pull request with final approval from at least one Give Lively engineer.
|
221
|
+
|
222
|
+
2. When creating a pull request, ensure that your code changes include an update to the gem's [version number](https://github.com/givelively/gl_command/blob/main/lib/gl_command/version.rb) using [semantic versioning](https://semver.org/)
|
223
|
+
|
224
|
+
3. After getting approval, merge your changes to `main`.
|
225
|
+
|
226
|
+
4. Once your CI build finishes successfully, pull the latest version of `main` locally.
|
227
|
+
|
228
|
+
5. Run the command `gem build`. This bundles the relevant files from the gem and prepares it to be published to [rubygems.org](https://rubygems.org/).
|
229
|
+
|
230
|
+
6. This will create a new file locally that looks like `gl_command-<new_gem_version_number>.gem`.
|
231
|
+
|
232
|
+
7. Run `gem push gl_command-<new_gem_version_number>.gem` to publish the new version
|
233
|
+
|
234
|
+
**NOTE: only the gem owners listed on rubygems can publish new versions**
|
235
|
+
|
218
236
|
---
|
219
237
|
|
220
238
|
This library is influenced by [interactors](https://github.com/collectiveidea/interactor) and inspired by the [Command Pattern](https://en.wikipedia.org/wiki/Command_pattern).
|
data/lib/gl_command/callable.rb
CHANGED
@@ -6,6 +6,7 @@ require 'gl_command/validatable'
|
|
6
6
|
|
7
7
|
module GLCommand
|
8
8
|
class Callable
|
9
|
+
include GLCommand::Validatable
|
9
10
|
ALWAYS_RAISE_ERRORS = ENV['GL_COMMAND_ALWAYS_RAISE'] == 'true'
|
10
11
|
DEFAULT_OPTS = { raise_errors: false, skip_unknown_parameters: true, in_chain: false }.freeze
|
11
12
|
RESERVED_WORDS = (DEFAULT_OPTS.keys + GLCommand::ChainableContext.reserved_words).sort.freeze
|
@@ -102,8 +103,6 @@ module GLCommand
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
|
-
include GLCommand::Validatable
|
106
|
-
|
107
106
|
attr_reader :context
|
108
107
|
|
109
108
|
def initialize(context = nil)
|
@@ -203,6 +202,7 @@ module GLCommand
|
|
203
202
|
|
204
203
|
chain_rollback if self.class.chain? # defined in GLCommand::Chainable
|
205
204
|
rollback
|
205
|
+
instrument_command(:after_rollback)
|
206
206
|
end
|
207
207
|
|
208
208
|
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
data/lib/gl_command/chainable.rb
CHANGED
@@ -41,7 +41,7 @@ module GLCommand
|
|
41
41
|
|
42
42
|
commands.map do |command|
|
43
43
|
cargs = context.chain_arguments_and_returns.slice(*command.arguments)
|
44
|
-
.merge(context.opts_hash).merge(in_chain:
|
44
|
+
.merge(context.opts_hash).merge(in_chain: context)
|
45
45
|
|
46
46
|
# using _result to make sure it doesn't cause naming conflicts with other uses of result
|
47
47
|
_result = command.call(**cargs)
|
data/lib/gl_command/context.rb
CHANGED
@@ -22,7 +22,7 @@ module GLCommand
|
|
22
22
|
{ raise_errors: raise_errors? }
|
23
23
|
end
|
24
24
|
|
25
|
-
attr_reader :klass, :error
|
25
|
+
attr_reader :klass, :error, :in_chain
|
26
26
|
attr_writer :full_error_message
|
27
27
|
|
28
28
|
# If someone calls #errors, they expect to get the errors! Include the non-validation error, if it exists
|
@@ -35,10 +35,6 @@ module GLCommand
|
|
35
35
|
false
|
36
36
|
end
|
37
37
|
|
38
|
-
def in_chain?
|
39
|
-
@in_chain
|
40
|
-
end
|
41
|
-
|
42
38
|
def returns
|
43
39
|
@klass.returns.index_with { |rattr| send(rattr) }
|
44
40
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module GLCommand
|
2
4
|
class ContextInspect
|
5
|
+
PERMITTED_OUTPUTS = %i[string hash].freeze
|
6
|
+
|
3
7
|
class << self
|
4
8
|
def error(error_obj)
|
5
9
|
return '' if error_obj.blank?
|
@@ -7,35 +11,50 @@ module GLCommand
|
|
7
11
|
error_obj.is_a?(Array) ? error_obj.uniq.join(', ') : error_obj.to_s
|
8
12
|
end
|
9
13
|
|
10
|
-
def hash_params(hash)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
elsif value.respond_to?(:uuid)
|
18
|
-
object_param_with_id(value, :uuid)
|
19
|
-
elsif value.respond_to?(:id)
|
20
|
-
object_param_with_id(value, :id)
|
21
|
-
else
|
22
|
-
value
|
23
|
-
end
|
24
|
-
"#{key}: #{value_s}"
|
25
|
-
end.join(', ')
|
14
|
+
def hash_params(hash, output: :string)
|
15
|
+
unless PERMITTED_OUTPUTS.include?(output)
|
16
|
+
raise "Unknown output type: #{output}, must be one of #{PERMITTED_OUTPUTS}"
|
17
|
+
end
|
18
|
+
|
19
|
+
result = hash.map { |key, value| output_for(key:, value:, output:) }
|
20
|
+
output == :string ? result.join(', ') : result.to_h
|
26
21
|
end
|
27
22
|
|
28
23
|
private
|
29
24
|
|
25
|
+
def output_for(key:, value:, output:)
|
26
|
+
value_s = if value.nil?
|
27
|
+
'nil'
|
28
|
+
elsif value.respond_to?(:to_sql)
|
29
|
+
object_param_as_sql(value, output:)
|
30
|
+
elsif value.respond_to?(:id)
|
31
|
+
object_param_with_id(value, :id, output:)
|
32
|
+
elsif value.respond_to?(:uuid)
|
33
|
+
object_param_with_id(value, :uuid, output:)
|
34
|
+
else
|
35
|
+
value
|
36
|
+
end
|
37
|
+
|
38
|
+
output == :string ? "#{key}: #{value_s}" : [key, value_s]
|
39
|
+
end
|
40
|
+
|
30
41
|
# Active record objects can be really big - rather than rendering the whole object, just show the ID
|
31
|
-
def object_param_with_id(obj, key)
|
42
|
+
def object_param_with_id(obj, key, output:)
|
32
43
|
obj_id = obj.send(key)
|
33
|
-
|
34
|
-
|
44
|
+
if output == :string
|
45
|
+
id_value = obj_id.is_a?(Integer) ? obj_id : "\"#{obj_id}\""
|
46
|
+
"#<#{obj.class.name} #{key}=#{id_value}>"
|
47
|
+
else
|
48
|
+
obj_id
|
49
|
+
end
|
35
50
|
end
|
36
51
|
|
37
|
-
def object_param_as_sql(obj)
|
38
|
-
|
52
|
+
def object_param_as_sql(obj, output:)
|
53
|
+
if output == :string
|
54
|
+
"#<#{obj.class.name} sql=\"#{obj.to_sql}\">"
|
55
|
+
else
|
56
|
+
obj.to_sql
|
57
|
+
end
|
39
58
|
end
|
40
59
|
end
|
41
60
|
end
|
data/lib/gl_command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gl_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Give Lively
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|