acts_as_versioner 1.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/acts_as_versioner.gemspec +2 -2
- data/lib/acts_as_versioner.rb +2 -1
- data/lib/acts_as_versioner/acts_as_versioner.rb +11 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf3d13dbd86c5a13e69d319ca761ce4eb027e4a7
|
4
|
+
data.tar.gz: ac7cbac9c20887bf3ff8b23929ea2699122d5ac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab2a1f735b7bb4b08b39c84f1617afdf0ae90b1d4280be318fa5a5ac6b4f5d852714285522292c1e8a20658d93d8bd2d24ce24024bb49446acbb3142b6222adb
|
7
|
+
data.tar.gz: 310179d467124ecc80834f36fb5003a3a2e6efe8510dde32adacaaa8068716c3571161fb3cd36250a52b20a4a27e88ada5031af421309c13d9be5b40cd14e262
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.0.3
|
data/acts_as_versioner.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "acts_as_versioner"
|
3
|
-
s.version = "1.0"
|
3
|
+
s.version = "1.0.3"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Markus Hediger"]
|
7
|
-
s.date = "2018-
|
7
|
+
s.date = "2018-07-23"
|
8
8
|
s.description = "Versioning of ar tables"
|
9
9
|
s.email = "m.hed@gmx.ch"
|
10
10
|
s.extra_rdoc_files = [
|
data/lib/acts_as_versioner.rb
CHANGED
@@ -2,7 +2,8 @@ require File.dirname(__FILE__) + '/acts_as_versioner/acts_as_versioner.rb'
|
|
2
2
|
require File.dirname(__FILE__) + '/acts_as_versioner/userstamp.rb'
|
3
3
|
module ActiveRecord::Acts::Versioner
|
4
4
|
@@configurator = {
|
5
|
-
:default_versioned_class_name => '
|
5
|
+
:default_versioned_class_name => 'Version',
|
6
|
+
:default_versioned_table_name => '_versions',
|
6
7
|
:default_versioned_created_at => 'created_at',
|
7
8
|
:default_versioned_updated_at => 'updated_at',
|
8
9
|
:default_versioned_created_by => 'created_by',
|
@@ -25,8 +25,8 @@ module ActiveRecord
|
|
25
25
|
|
26
26
|
send :attr_accessor
|
27
27
|
|
28
|
-
self.versioned_class_name = options[:class_name] || "#{base_class}
|
29
|
-
self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}#{ActiveRecord::Acts::Versioner::configurator[:
|
28
|
+
self.versioned_class_name = options[:class_name] || "#{base_class}#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_class_name]}"
|
29
|
+
self.versioned_table_name = options[:table_name] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_table_name]}#{table_name_suffix}"
|
30
30
|
self.versioned_foreign_key = options[:versioned_foreign_key] || "#{table_name_prefix}#{base_class.name.demodulize.underscore}_id" # quick 'n' dirty fix
|
31
31
|
|
32
32
|
if block_given?
|
@@ -63,12 +63,12 @@ module ActiveRecord
|
|
63
63
|
|
64
64
|
# Returns the current version.
|
65
65
|
def get_current_version
|
66
|
-
instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} desc, id desc").first
|
66
|
+
instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order(Arel.sql("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} desc, id desc")).first
|
67
67
|
end
|
68
68
|
|
69
69
|
# Returns all versions of a model.
|
70
70
|
def get_versions
|
71
|
-
instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, id asc").all
|
71
|
+
instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order(Arel.sql("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, id asc")).all
|
72
72
|
end
|
73
73
|
|
74
74
|
# This methods returns all versions of associated tables (table that belong to the existing model).
|
@@ -77,7 +77,7 @@ module ActiveRecord
|
|
77
77
|
stack = Array.new # Stack of the same algorithm.
|
78
78
|
|
79
79
|
# Initiate algorithm with the used model
|
80
|
-
versions = instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, #{ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at]} asc").all
|
80
|
+
versions = instance_eval(self.versioned_class_name).where([self.versioned_foreign_key + ' = ?', self.id]).order(Arel.sql("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, #{ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at]} asc")).all
|
81
81
|
associations[self.versioned_class_name] = versions # Caching itself in the result hash
|
82
82
|
stack.push self.class => versions # Setting itself onto the stack
|
83
83
|
|
@@ -118,7 +118,7 @@ module ActiveRecord
|
|
118
118
|
}
|
119
119
|
|
120
120
|
unless foreign_ids.blank?
|
121
|
-
tmp_new_data_set = association_klass.versioned_class.where(["#{class_name.to_s.tableize.singularize.downcase}_id IN (?)", foreign_ids]).order("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, #{ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at]} asc").all
|
121
|
+
tmp_new_data_set = association_klass.versioned_class.where(["#{class_name.to_s.tableize.singularize.downcase}_id IN (?)", foreign_ids]).order(Arel.sql("#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_updated_at]} asc, #{ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at]} asc")).all
|
122
122
|
unless tmp_new_data_set.blank? then new_data_set.concat(tmp_new_data_set) end
|
123
123
|
end
|
124
124
|
|
@@ -168,7 +168,7 @@ module ActiveRecord
|
|
168
168
|
def prepare_versioning(mode = 0)
|
169
169
|
@acts_as_versioner_mode = mode # mode : 0 = insert, 1 = update, 2 = delete
|
170
170
|
@acts_as_versioner_model = self.dup
|
171
|
-
|
171
|
+
@acts_as_versioner_model.updated_at = Time.now
|
172
172
|
|
173
173
|
if mode == 0 && self.id != nil then @acts_as_versioner_mode = 1 end
|
174
174
|
end
|
@@ -186,6 +186,9 @@ module ActiveRecord
|
|
186
186
|
|
187
187
|
attributes[self.versioned_foreign_key] = self.id
|
188
188
|
attributes[:action] = @acts_as_versioner_mode
|
189
|
+
|
190
|
+
# Conserve the created_at field in the versions table
|
191
|
+
attributes[ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at].to_sym] = self[ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at].to_sym]
|
189
192
|
|
190
193
|
modelversion = instance_eval(self.versioned_class_name).new(attributes)
|
191
194
|
modelversion.save(:validate => false)
|
@@ -215,7 +218,7 @@ module ActiveRecord
|
|
215
218
|
|
216
219
|
# Rake migration task to create the versioned table
|
217
220
|
def create_versioned_table(create_table_options = {})
|
218
|
-
versioned_table_name = self.to_s.underscore
|
221
|
+
versioned_table_name = "#{self.to_s.underscore}#{ActiveRecord::Acts::Versioner::configurator[:default_versioned_table_name]}"
|
219
222
|
puts table_name
|
220
223
|
# create version column in main table if it does not exist
|
221
224
|
add_column_to_table(table_name, ActiveRecord::Acts::Versioner::configurator[:default_versioned_created_at], :datetime)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_versioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Markus Hediger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
requirements: []
|
103
103
|
rubyforge_project:
|
104
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.5.2
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: Versioning of ar tables
|