hoardable 0.19.2 → 0.19.3

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: affe4a55357ac085a712046c50d2742c7f1887947dee2a7e4d221cf5c7fd7086
4
- data.tar.gz: 7b2112637801d32e5f18a93d3aa54077e631d25fd9ef6a85639770910d87024b
3
+ metadata.gz: 27747103c387757c5faf3cf3771651d221d67b8367d5b6f6623a34c43b3afe9d
4
+ data.tar.gz: 4abd9206358508019a69273c33fe9d772ad28b9ea4f76f85f499315b17bd99c2
5
5
  SHA512:
6
- metadata.gz: dfdf425df919edd8abce1942108881469c3c29b4e3e0ac9641ab56c221a6c0496f73ae7b6c657aa3edf33ae31b265e15d245e1e4d6e41fedbcbc7983af0657f9
7
- data.tar.gz: 04b2495a301dd95bdd8d7f4af56ea6cf6dac682d7da59e59dee6d40ed031451410344a34f9580551047985009fc17e5ce1ac0e6d83c0a6f531ec071e932788d7
6
+ metadata.gz: a771a19b506f170a17fd672219a4899dcbfebc55e9ab2422a2d22198d0efd6c13667e5fbb2c69e1da724222bb9f9923fc4263f7b3ae14b3e260c62cc22eb42fd
7
+ data.tar.gz: c8eab3064758767b33f46943f0e09544e096545ad3f436c3b43e237d5be6e11589bc7840241561ddd04f860a1371656285badcd3a890cc003244829d6abf4010
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.19.3
2
+
3
+ - Support providing `event_uuid` in `with`.
4
+
1
5
  ## 0.19.2
2
6
 
3
7
  - Consult `inheritance_column` when constructing default scope
@@ -19,7 +19,7 @@ module Hoardable
19
19
  returning: source_primary_key.to_sym
20
20
  )
21
21
  version_id = version[0][source_primary_key]
22
- source_record.instance_variable_set("@hoardable_version", version_class.find(version_id))
22
+ source_record.instance_variable_set(:@hoardable_version, version_class.find(version_id))
23
23
  source_record.run_callbacks(:versioned, &block)
24
24
  end
25
25
 
@@ -28,7 +28,8 @@ module Hoardable
28
28
  end
29
29
 
30
30
  def find_or_initialize_hoardable_event_uuid
31
- Thread.current[:hoardable_event_uuid] ||= SecureRandom.uuid
31
+ Thread.current[:hoardable_event_uuid] ||= Thread.current[:contextual_event_uuid] ||
32
+ SecureRandom.uuid
32
33
  end
33
34
 
34
35
  def initialize_version_attributes(operation)
@@ -92,7 +93,7 @@ module Hoardable
92
93
 
93
94
  def initialize_temporal_range
94
95
  upper_bound = Thread.current[:hoardable_travel_to] || Time.now.utc
95
- lower_bound = (previous_temporal_tsrange_end || hoardable_source_epoch)
96
+ lower_bound = previous_temporal_tsrange_end || hoardable_source_epoch
96
97
 
97
98
  if upper_bound < lower_bound
98
99
  raise InvalidTemporalUpperBoundError.new(upper_bound, lower_bound)
@@ -112,7 +113,7 @@ module Hoardable
112
113
  end
113
114
 
114
115
  def unset_hoardable_version_and_event_uuid
115
- source_record.instance_variable_set("@hoardable_version", nil)
116
+ source_record.instance_variable_set(:@hoardable_version, nil)
116
117
  return if source_record.class.connection.transaction_open?
117
118
 
118
119
  Thread.current[:hoardable_event_uuid] = nil
@@ -46,13 +46,13 @@ module Hoardable
46
46
  CONFIG_KEYS.each do |key|
47
47
  define_method(key) { hoardable_config[key] }
48
48
 
49
- define_method("#{key}=") { |value| @config[key] = value }
49
+ define_method(:"#{key}=") { |value| @config[key] = value }
50
50
  end
51
51
 
52
52
  DATA_KEYS.each do |key|
53
53
  define_method(key) { hoardable_context[key] }
54
54
 
55
- define_method("#{key}=") { |value| @context[key] = value }
55
+ define_method(:"#{key}=") { |value| @context[key] = value }
56
56
  end
57
57
 
58
58
  # This is a general use method for setting {file:README.md#tracking-contextual-data Contextual
@@ -63,18 +63,32 @@ module Hoardable
63
63
  thread = Thread.current
64
64
  current_thread_config = thread[:hoardable_config]
65
65
  current_thread_context = thread[:hoardable_context]
66
+
67
+ if hash.include?(:event_uuid)
68
+ contextual_event_uuid = hash[:event_uuid]
69
+ unless valid_event_uuid?(contextual_event_uuid)
70
+ raise InvalidEventUUID, contextual_event_uuid
71
+ end
72
+ thread[:contextual_event_uuid] = contextual_event_uuid
73
+ end
74
+
66
75
  thread[:hoardable_config] = hoardable_config.merge(hash.slice(*CONFIG_KEYS))
67
76
  thread[:hoardable_context] = hoardable_context.merge(hash.slice(*DATA_KEYS))
68
77
  yield
69
78
  ensure
70
79
  thread[:hoardable_config] = current_thread_config
71
80
  thread[:hoardable_context] = current_thread_context
81
+ thread[:contextual_event_uuid] = nil
72
82
  end
73
83
 
74
84
  private def hoardable_config
75
85
  @config.merge(Thread.current[:hoardable_config] ||= {})
76
86
  end
77
87
 
88
+ private def valid_event_uuid?(value)
89
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.match?(value.to_s.downcase)
90
+ end
91
+
78
92
  private def hoardable_context
79
93
  @context.merge(Thread.current[:hoardable_context] ||= {})
80
94
  end
@@ -122,7 +136,7 @@ module Hoardable
122
136
  initializer "hoardable.schema_statements" do
123
137
  ActiveSupport.on_load(:active_record_postgresqladapter) do
124
138
  # We need to control the table dumping order of tables, so revert these to just +super+
125
- Fx::SchemaDumper.module_eval("def tables(streams); super; end")
139
+ Fx::SchemaDumper.module_eval("def tables(streams); super; end", __FILE__, __LINE__)
126
140
 
127
141
  ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaDumper.prepend(SchemaDumper)
128
142
  ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements.prepend(SchemaStatements)
@@ -9,9 +9,9 @@ module Hoardable
9
9
  class CreatedAtColumnMissingError < Error
10
10
  def initialize(source_table_name)
11
11
  super(<<~LOG)
12
- '#{source_table_name}' does not have a 'created_at' column, so the start of the first
13
- version’s temporal period cannot be known. Add a 'created_at' column to '#{source_table_name}'.
14
- LOG
12
+ '#{source_table_name}' does not have a 'created_at' column, so the start of the first
13
+ version’s temporal period cannot be known. Add a 'created_at' column to '#{source_table_name}'.
14
+ LOG
15
15
  end
16
16
  end
17
17
 
@@ -19,9 +19,9 @@ module Hoardable
19
19
  class UpdatedAtColumnMissingError < Error
20
20
  def initialize(source_table_name)
21
21
  super(<<~LOG)
22
- '#{source_table_name}' does not have an 'updated_at' column, so Hoardable cannot look up
23
- associated record versions with it. Add an 'updated_at' column to '#{source_table_name}'.
24
- LOG
22
+ '#{source_table_name}' does not have an 'updated_at' column, so Hoardable cannot look up
23
+ associated record versions with it. Add an 'updated_at' column to '#{source_table_name}'.
24
+ LOG
25
25
  end
26
26
  end
27
27
 
@@ -29,9 +29,18 @@ module Hoardable
29
29
  class InvalidTemporalUpperBoundError < Error
30
30
  def initialize(upper, lower)
31
31
  super(<<~LOG)
32
- 'The supplied value to `Hoardable.travel_to` (#{upper}) is before the calculated lower bound (#{lower}).
33
- You must provide a datetime > the lower bound.
34
- LOG
32
+ 'The supplied value to `Hoardable.travel_to` (#{upper}) is before the calculated lower bound (#{lower}).
33
+ You must provide a datetime > the lower bound.
34
+ LOG
35
+ end
36
+ end
37
+
38
+ # An error to be raised when an invalid (non-UUID) value is provided as an event_uuid
39
+ class InvalidEventUUID < Error
40
+ def initialize(value)
41
+ super(<<~LOG)
42
+ 'The supplied 'event_uuid' value must be a valid UUID'
43
+ LOG
35
44
  end
36
45
  end
37
46
  end
@@ -10,6 +10,7 @@ module Hoardable
10
10
  super
11
11
  dump_inherited_tables(stream)
12
12
  empty_line(stream)
13
+ functions(stream)
13
14
  triggers(stream)
14
15
  end
15
16
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hoardable
4
- VERSION = "0.19.2"
4
+ VERSION = "0.19.3"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoardable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.2
4
+ version: 0.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - justin talbott
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-04-08 00:00:00.000000000 Z
10
+ date: 2025-11-10 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activerecord