iron_trail 0.1.3 → 0.1.5

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: eddde7b02bdbba2a0c1aa1c19ee3b94ec7b072b9997efbbe448ca08df57b259a
4
- data.tar.gz: aef0e076c736ce71b549ce25e92a5e2c4787c98a511ac4cd99c9378947ee26eb
3
+ metadata.gz: acc0c129e94301696b7af3b839fded014206cff27dda2255e82ade79f4ec7f9f
4
+ data.tar.gz: 177a3a0723fb6e07a070e7b943c55f8305b9f5e48e24c61d7f970c056314a486
5
5
  SHA512:
6
- metadata.gz: 8c44cfbb096061ab84e56d0185fd8f70cd499e8be74719dbbbce8e2c9dd19b87280a7781ab40efde0b3cd982ae9bfd3b789701fd4763d334d8f839fbfd199671
7
- data.tar.gz: b63a94044f453db750308883742d359871dc5598df6c83d6be91731d82c0087d29f66955aa09f57131611f38efce48c8c8e940ab7ea0b3a295017e4ed9c98222
6
+ metadata.gz: 7ab4b672dc659c6cc4b4eb1b36c0b621113d9f6dbb600f63d2e4affb9b75d9c7120ade90487d1c4c1c88bb2f4155cfc7db725335de7011d2d3577200396a4596
7
+ data.tar.gz: 1ede396ea029503f12bcea7838fea1819543501e9efdf1814c1354ea356268b6e9f9f91114b9711332cde0e26240559a193b2c9c8152ed0390657b42a02b908c
@@ -21,17 +21,39 @@ module IronTrail
21
21
  _where_object_changes(0, args)
22
22
  end
23
23
 
24
+ # Allows filtering out updates that changed just a certain set of columns.
25
+ # This could be useful, for instance, to filter out updates made with
26
+ # ActiveRecord's #touch method, which changes only the updated_at column.
27
+ # In that case, calling `.with_delta_other_than(:updated_at)` would exclude
28
+ # such changes from the result.
29
+ #
30
+ # This works by inspecting whether there are any keys in the rec_delta column
31
+ # other than the columns specified in the `columns` parameter.
32
+ def with_delta_other_than(*columns)
33
+ quoted_columns = columns.map { |col_name| connection.quote(col_name) }
34
+ exclude_array = "ARRAY[#{quoted_columns.join(', ')}]::text[]"
35
+
36
+ sql = "rec_delta IS NULL OR (rec_delta - #{exclude_array}) <> '{}'::jsonb"
37
+ where(::Arel::Nodes::SqlLiteral.new(sql))
38
+ end
39
+
24
40
  private
25
41
 
26
42
  def _where_object_changes(ary_index, args)
43
+ ary_index = Integer(ary_index)
27
44
  scope = all
28
45
 
29
46
  args.each do |col_name, value|
30
- scope.where!(
31
- ::Arel::Nodes::SqlLiteral.new("rec_delta->#{connection.quote col_name}->>#{Integer(ary_index)}").eq(
32
- ::Arel::Nodes::BindParam.new(value)
47
+ col_delta = "rec_delta->#{connection.quote(col_name)}"
48
+ node = if value == nil
49
+ ::Arel::Nodes::SqlLiteral.new("#{col_delta}->#{ary_index} = 'null'::jsonb")
50
+ else
51
+ ::Arel::Nodes::SqlLiteral.new("#{col_delta}->>#{ary_index}").eq(
52
+ ::Arel::Nodes::BindParam.new(value.to_s)
33
53
  )
34
- )
54
+ end
55
+
56
+ scope.where!(node)
35
57
  end
36
58
 
37
59
  scope
@@ -10,6 +10,8 @@ module IronTrail
10
10
  end
11
11
 
12
12
  def self.merge_metadata(keys, merge_hash)
13
+ raise TypeError.new("value must be a Hash") unless merge_hash.is_a?(Hash)
14
+
13
15
  self.metadata ||= {}
14
16
  base = self.metadata
15
17
  keys.each do |key|
@@ -10,9 +10,8 @@ module IronTrail
10
10
 
11
11
  source_attributes.each do |name, value|
12
12
  if record.has_attribute?(name)
13
- record[name.to_sym] = value
14
- elsif record.respond_to?("#{name}=")
15
- record.send("#{name}=", value)
13
+ attr_type = record.type_for_attribute(name)
14
+ record[name] = attr_type.deserialize(value)
16
15
  else
17
16
  ghost = record.instance_variable_get(:@irontrail_reified_ghost_attributes)
18
17
  unless ghost
@@ -9,6 +9,20 @@ require 'iron_trail'
9
9
 
10
10
  module IronTrail
11
11
  module Testing
12
+ module InstanceMethods
13
+ def irontrail_set_actor(actor)
14
+ if actor.nil?
15
+ IronTrail::Current.metadata.delete(:_actor_type)
16
+ IronTrail::Current.metadata.delete(:_actor_id)
17
+ else
18
+ IronTrail::Current.merge_metadata([], {
19
+ _actor_type: actor.class.name,
20
+ _actor_id: actor.id
21
+ })
22
+ end
23
+ end
24
+ end
25
+
12
26
  class << self
13
27
  attr_accessor :enabled
14
28
 
@@ -56,11 +70,18 @@ module IronTrail
56
70
  end
57
71
 
58
72
  RSpec.configure do |config|
73
+ config.include ::IronTrail::Testing::InstanceMethods
74
+
59
75
  config.around(:each, iron_trail: true) do |example|
60
76
  IronTrail::Testing.with_iron_trail(want_enabled: true) { example.run }
61
77
  end
78
+
62
79
  config.around(:each, iron_trail: false) do |example|
63
80
  raise "Using iron_trail: false does not do what you might think it does. To disable iron_trail, " \
64
81
  "use IronTrail::Testing.with_iron_trail(want_enabled: false) { ... } instead."
65
82
  end
83
+
84
+ config.before(:each) do
85
+ IronTrail::Current.reset
86
+ end
66
87
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_literal_string: true
2
2
 
3
3
  module IronTrail
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.5'
5
5
  end
data/lib/iron_trail.rb CHANGED
@@ -30,7 +30,9 @@ module IronTrail
30
30
 
31
31
  module SchemaDumper
32
32
  def trailer(stream)
33
- stream.print "\n IronTrail.post_schema_load(self, missing_tracking: @irontrail_missing_track)\n"
33
+ if IronTrail.enabled?
34
+ stream.print "\n IronTrail.post_schema_load(self, missing_tracking: @irontrail_missing_track)\n"
35
+ end
34
36
 
35
37
  super(stream)
36
38
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_trail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Diego Piske
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -160,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  - !ruby/object:Gem::Version
161
161
  version: '0'
162
162
  requirements: []
163
- rubygems_version: 3.6.2
163
+ rubygems_version: 3.6.7
164
164
  specification_version: 4
165
165
  summary: Creates a trail strong as iron
166
166
  test_files: []