iron_trail 0.1.5 → 0.1.7
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 +40 -3
- data/lib/iron_trail/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: c6a42eb93e3876f57d47428ebc0b06a640df92762210caa1832c046f90508fc3
|
|
4
|
+
data.tar.gz: 42e3bf5b3578192d014e38de9c72ced67d5d5cd9d21899b860454234f1da8b05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc586e08db3fce51c0c16405e29a64dc90a82d4beecfb74517448e827371911ccb9562ce79fe79c8cacd513044e0e49238035bbd8fb851c28656aba409b20721
|
|
7
|
+
data.tar.gz: 3a4a07c2d361de5c7d4484c273b3df5e98c418bd61bca1910adf448b652b9ec2025acc9b13871620244b44cbcd465dda2572f672c30bb877adf524b18da75b0d
|
|
@@ -4,13 +4,50 @@ module IronTrail
|
|
|
4
4
|
module ChangeModelConcern
|
|
5
5
|
extend ::ActiveSupport::Concern
|
|
6
6
|
|
|
7
|
+
def insert_operation? = (operation == 'i')
|
|
8
|
+
def update_operation? = (operation == 'u')
|
|
9
|
+
def delete_operation? = (operation == 'd')
|
|
10
|
+
|
|
7
11
|
def reify
|
|
8
12
|
Reifier.reify(self)
|
|
9
13
|
end
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
# We don't store the class name of the object, but we do store the rec_table.
|
|
16
|
+
# This method infers the class name from the rec_table and also the "type"
|
|
17
|
+
# attribute in the stored object in case it's a rails STI class.
|
|
18
|
+
#
|
|
19
|
+
# It returns the class instance. Raises an error in case the class couldn't
|
|
20
|
+
# be inferred.
|
|
21
|
+
def rec_class
|
|
22
|
+
source_attributes = (delete_operation? ? rec_old : rec_new)
|
|
23
|
+
Reifier.model_from_table_name(rec_table, source_attributes.fetch('type', nil))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# This mimics the method with the same name available in the papertrail gem.
|
|
27
|
+
# It is an extended rec_delta, where attributes values are properly deserialized
|
|
28
|
+
# as rails' ActiveRecord would do.
|
|
29
|
+
#
|
|
30
|
+
# For instance, timestamps are serialized as strings in JSON, so rec_delta
|
|
31
|
+
# would return strings for timestamps. Using this method, it'd return a proper
|
|
32
|
+
# timestamp deserialized from the string.
|
|
33
|
+
#
|
|
34
|
+
# This method doesn't do caching and always computes the full thing. It's
|
|
35
|
+
# up to the user to perform caching if wanted.
|
|
36
|
+
def compute_changeset
|
|
37
|
+
return nil unless update_operation?
|
|
38
|
+
return nil unless rec_delta.present?
|
|
39
|
+
|
|
40
|
+
klass = rec_class
|
|
41
|
+
|
|
42
|
+
HashWithIndifferentAccess.new.tap do |changes|
|
|
43
|
+
rec_delta.each do |col_name, in_delta|
|
|
44
|
+
type_class = klass.type_for_attribute(col_name)
|
|
45
|
+
out_delta = in_delta.map { |val| type_class.deserialize(val) }
|
|
46
|
+
|
|
47
|
+
changes[col_name] = out_delta
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
14
51
|
|
|
15
52
|
module ClassMethods
|
|
16
53
|
def where_object_changes_to(args = {})
|
data/lib/iron_trail/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- André Diego Piske
|
|
@@ -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.9
|
|
164
164
|
specification_version: 4
|
|
165
165
|
summary: Creates a trail strong as iron
|
|
166
166
|
test_files: []
|