iron_trail 0.0.2 → 0.0.4
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/association.rb +7 -0
- data/lib/iron_trail/change_model_concern.rb +8 -0
- data/lib/iron_trail/collection_proxy_mixin.rb +16 -0
- data/lib/iron_trail/model.rb +1 -0
- data/lib/iron_trail/reflection.rb +2 -0
- data/lib/iron_trail/reifier.rb +52 -0
- data/lib/iron_trail/version.rb +1 -1
- data/lib/iron_trail.rb +2 -0
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b26e21161b7a8685eb9522dd6dc8e5856a8573258016a4cb69aa526eab3ca672
|
4
|
+
data.tar.gz: f54a66d2bf06b346e7429b8d47ef3018448184a4135b9a6d62e74b2588607d59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 367db0c530f76d9720689ba997ba0f94e57fa007088130a7b9ce76828d42455f41077433e8312523a7415dd3dc4429b167c4e8029dca2f1843fe1411c9e0da4d
|
7
|
+
data.tar.gz: b6179bf73bcf3d03d8957a4dded91a08242f9aca7196cb8ad4223cca35af5ac1f482098694768f5650ce45065bea159afd4240b936444259c5234807a248311b
|
@@ -4,6 +4,14 @@ module IronTrail
|
|
4
4
|
module ChangeModelConcern
|
5
5
|
extend ::ActiveSupport::Concern
|
6
6
|
|
7
|
+
def reify
|
8
|
+
Reifier.reify(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert_operation? = (operation == 'i')
|
12
|
+
def update_operation? = (operation == 'u')
|
13
|
+
def delete_operation? = (operation == 'd')
|
14
|
+
|
7
15
|
module ClassMethods
|
8
16
|
def where_object_changes_to(args = {})
|
9
17
|
_where_object_changes(1, args)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IronTrail
|
4
|
+
module CollectionProxyMixin
|
5
|
+
def travel_to(ts)
|
6
|
+
arel_table = arel.ast.cores.first.source.left
|
7
|
+
|
8
|
+
change_record = scope
|
9
|
+
.order(arel_table[:created_at] => :desc)
|
10
|
+
.where(arel_table[:created_at].lteq(ts))
|
11
|
+
.first
|
12
|
+
|
13
|
+
change_record.reify
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/iron_trail/model.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module IronTrail
|
4
|
+
module Reifier
|
5
|
+
def self.reify(trail)
|
6
|
+
source_attributes = (trail.delete_operation? ? trail.rec_old : trail.rec_new)
|
7
|
+
klass = model_from_table_name(trail.rec_table, source_attributes['type'])
|
8
|
+
|
9
|
+
record = klass.where(id: trail.rec_id).first || klass.new
|
10
|
+
|
11
|
+
source_attributes.each do |name, value|
|
12
|
+
if record.has_attribute?(name)
|
13
|
+
record[name.to_sym] = value
|
14
|
+
elsif record.respond_to?("#{name}=")
|
15
|
+
record.send("#{name}=", value)
|
16
|
+
else
|
17
|
+
ghost = record.instance_variable_get(:@irontrail_reified_ghost_attributes)
|
18
|
+
unless ghost
|
19
|
+
ghost = HashWithIndifferentAccess.new
|
20
|
+
record.instance_variable_set(:@irontrail_reified_ghost_attributes, ghost)
|
21
|
+
end
|
22
|
+
ghost[name] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
record
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.model_from_table_name(table_name, sti_type=nil)
|
30
|
+
index = ActiveRecord::Base.descendants.reject(&:abstract_class).chunk(&:table_name).to_h do |key, val|
|
31
|
+
v = \
|
32
|
+
if val.length == 1
|
33
|
+
val[0]
|
34
|
+
else
|
35
|
+
val.to_h { |k| [k.to_s, k] }
|
36
|
+
end
|
37
|
+
|
38
|
+
[key, v]
|
39
|
+
end
|
40
|
+
|
41
|
+
klass = index[table_name]
|
42
|
+
raise "Cannot infer model from table named '#{table_name}'" unless klass
|
43
|
+
|
44
|
+
return klass unless klass.is_a?(Hash)
|
45
|
+
klass = klass[sti_type]
|
46
|
+
|
47
|
+
return klass if klass
|
48
|
+
|
49
|
+
raise "Cannot infer STI model for table #{table_name} and type '#{sti_type}'"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/iron_trail/version.rb
CHANGED
data/lib/iron_trail.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Diego Piske
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
10
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
@@ -136,7 +135,6 @@ dependencies:
|
|
136
135
|
- - "~>"
|
137
136
|
- !ruby/object:Gem::Version
|
138
137
|
version: '7.2'
|
139
|
-
description:
|
140
138
|
email: andrepiske@gmail.com
|
141
139
|
executables: []
|
142
140
|
extensions: []
|
@@ -150,6 +148,7 @@ files:
|
|
150
148
|
- lib/iron_trail.rb
|
151
149
|
- lib/iron_trail/association.rb
|
152
150
|
- lib/iron_trail/change_model_concern.rb
|
151
|
+
- lib/iron_trail/collection_proxy_mixin.rb
|
153
152
|
- lib/iron_trail/config.rb
|
154
153
|
- lib/iron_trail/db_functions.rb
|
155
154
|
- lib/iron_trail/irontrail_log_row_function.sql
|
@@ -159,6 +158,7 @@ files:
|
|
159
158
|
- lib/iron_trail/query_transformer.rb
|
160
159
|
- lib/iron_trail/railtie.rb
|
161
160
|
- lib/iron_trail/reflection.rb
|
161
|
+
- lib/iron_trail/reifier.rb
|
162
162
|
- lib/iron_trail/sidekiq.rb
|
163
163
|
- lib/iron_trail/sidekiq_middleware.rb
|
164
164
|
- lib/iron_trail/testing/rspec.rb
|
@@ -168,7 +168,6 @@ homepage: https://github.com/trusted/iron_trail
|
|
168
168
|
licenses:
|
169
169
|
- MIT
|
170
170
|
metadata: {}
|
171
|
-
post_install_message:
|
172
171
|
rdoc_options: []
|
173
172
|
require_paths:
|
174
173
|
- lib
|
@@ -183,8 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
182
|
- !ruby/object:Gem::Version
|
184
183
|
version: '0'
|
185
184
|
requirements: []
|
186
|
-
rubygems_version: 3.
|
187
|
-
signing_key:
|
185
|
+
rubygems_version: 3.6.2
|
188
186
|
specification_version: 4
|
189
187
|
summary: Creates a trail strong as iron
|
190
188
|
test_files: []
|