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 +4 -4
- data/lib/iron_trail/change_model_concern.rb +26 -4
- data/lib/iron_trail/current.rb +2 -0
- data/lib/iron_trail/reifier.rb +2 -3
- data/lib/iron_trail/testing/rspec.rb +21 -0
- data/lib/iron_trail/version.rb +1 -1
- data/lib/iron_trail.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc0c129e94301696b7af3b839fded014206cff27dda2255e82ade79f4ec7f9f
|
4
|
+
data.tar.gz: 177a3a0723fb6e07a070e7b943c55f8305b9f5e48e24c61d7f970c056314a486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
data/lib/iron_trail/current.rb
CHANGED
data/lib/iron_trail/reifier.rb
CHANGED
@@ -10,9 +10,8 @@ module IronTrail
|
|
10
10
|
|
11
11
|
source_attributes.each do |name, value|
|
12
12
|
if record.has_attribute?(name)
|
13
|
-
|
14
|
-
|
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
|
data/lib/iron_trail/version.rb
CHANGED
data/lib/iron_trail.rb
CHANGED
@@ -30,7 +30,9 @@ module IronTrail
|
|
30
30
|
|
31
31
|
module SchemaDumper
|
32
32
|
def trailer(stream)
|
33
|
-
|
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.
|
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:
|
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.
|
163
|
+
rubygems_version: 3.6.7
|
164
164
|
specification_version: 4
|
165
165
|
summary: Creates a trail strong as iron
|
166
166
|
test_files: []
|