iron_trail 0.0.2 → 0.0.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 +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/reifier.rb +52 -0
- data/lib/iron_trail/version.rb +1 -1
- data/lib/iron_trail.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd13db21df61365c3749688097fbe2cecc39e13fdffeec89b82952306105ed30
|
4
|
+
data.tar.gz: fb18dbcf2ec368a3412bcbc96b67a25aa31285992335303878a051c6b2ece806
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f24d6c2460879b591d703fdf711a80e08ba9bda0a8353c832877790b58f586f2b72db69873cbebe33363953ae9d06a40cb2d059bbac564a11ec8fab3a55e390d
|
7
|
+
data.tar.gz: a0f434e388b67352d61d45ac5667d93f1a4f048e5dbc332437b205b6a23d9f4b272eb558d43fdffaf58dc1b15dee93aa8b1a9ac47746d5caf1a4fb50a3e7733f
|
@@ -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,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Diego Piske
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/iron_trail.rb
|
151
151
|
- lib/iron_trail/association.rb
|
152
152
|
- lib/iron_trail/change_model_concern.rb
|
153
|
+
- lib/iron_trail/collection_proxy_mixin.rb
|
153
154
|
- lib/iron_trail/config.rb
|
154
155
|
- lib/iron_trail/db_functions.rb
|
155
156
|
- lib/iron_trail/irontrail_log_row_function.sql
|
@@ -159,6 +160,7 @@ files:
|
|
159
160
|
- lib/iron_trail/query_transformer.rb
|
160
161
|
- lib/iron_trail/railtie.rb
|
161
162
|
- lib/iron_trail/reflection.rb
|
163
|
+
- lib/iron_trail/reifier.rb
|
162
164
|
- lib/iron_trail/sidekiq.rb
|
163
165
|
- lib/iron_trail/sidekiq_middleware.rb
|
164
166
|
- lib/iron_trail/testing/rspec.rb
|
@@ -183,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
185
|
- !ruby/object:Gem::Version
|
184
186
|
version: '0'
|
185
187
|
requirements: []
|
186
|
-
rubygems_version: 3.5.
|
188
|
+
rubygems_version: 3.5.21
|
187
189
|
signing_key:
|
188
190
|
specification_version: 4
|
189
191
|
summary: Creates a trail strong as iron
|