gl_command 1.2.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 705c23dec5e3038e7a6b4d0736f58589b775edd30ee53056d2478b8361f9a3d6
4
- data.tar.gz: a547c64df86a0f2a533ad43ea5f1ee0a1e2dfcc8fe27e6f1c85b4a018ad75b39
3
+ metadata.gz: d64529ae90558047a1a67fb4641fcbc6807f4bac0ef8b503945d2981dac33f80
4
+ data.tar.gz: 541c75d629f1ba4971ab7d6fd37ac4a1fdfee2f19cb6256477d4857408fb64ce
5
5
  SHA512:
6
- metadata.gz: b13e47c074cc18aeeb50cd0e874c088cd7c0091b52fc5d705b4b5b79ddbb18fa1b3d12b596bf2febd85264a1fe5f9e933fa0893444b21369a4a8cc4a3a33c64f
7
- data.tar.gz: 25ac2f9a597e199fef77ebcd08442937615b63102bd8e071d0aea68ede1a2e83da085e902022f54ed32a41ddcf474510e9be811f3dc37941b78f7a2498a0c383
6
+ metadata.gz: 7767272a19c79ed50bc21bcd5a94a04f8f16c26e509bdfc3b86937e8204dabf2d053ea2fc85919acc56de3a770fd35ff88490b2d101fdcf6e6a89a714c55176f
7
+ data.tar.gz: f4fd2347bedf5ccbd94c09e230bf760d16d0ec1f19a4ecada73416d7a4b0da52a7f79759f074c4a38f98cd783ce45a07dd84c46dd1f13b87685cfdec8d0e9c9e
@@ -202,6 +202,7 @@ module GLCommand
202
202
 
203
203
  chain_rollback if self.class.chain? # defined in GLCommand::Chainable
204
204
  rollback
205
+ instrument_command(:after_rollback)
205
206
  end
206
207
 
207
208
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -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
- hash.map do |key, value|
12
- value_s =
13
- if value.nil?
14
- 'nil'
15
- elsif value.respond_to?(:to_sql)
16
- object_param_as_sql(value)
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
- id_value = obj_id.is_a?(Integer) ? obj_id : "\"#{obj_id}\""
34
- "#<#{obj.class.name} #{key}=#{id_value}>"
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
- "#<#{obj.class.name} sql=\"#{obj.to_sql}\">"
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
@@ -1,3 +1,3 @@
1
1
  module GLCommand
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
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.2.0
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-04-01 00:00:00.000000000 Z
11
+ date: 2025-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord