rtiss_acts_as_versioned 0.9.2 → 0.10.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aa58c29bc182ff4d9c7c28aff6f7406e646db23a
4
- data.tar.gz: 457cd94cb009f45f01d953bba5b1b6ae155e785e
2
+ SHA256:
3
+ metadata.gz: 9cb2135a1af395ec8595624054f61c3e734f46e92afb672eb88c100ec022bf45
4
+ data.tar.gz: 7281b3e9f959d0927ccb11ea403ea1f2a3bae706fc6e82fda93628a783ee4384
5
5
  SHA512:
6
- metadata.gz: 87fd7d36c67f766c7b47eb3a5467ece59665002942f5fd711a7ddeaf96231479cbfa1c4a14af2f3db76cfaf583e22421547167f62c4f06b1096d8c96670d58ab
7
- data.tar.gz: 5f2fe84016f43dff43e8d8472b4431b942aa8f5afaa8839c4e306e0a02e0ce1ff3167c304cdbb9853d34e756e94df53d1be66a31565be351156d2d865b8c6986
6
+ metadata.gz: c081c4d01d6dbd52000378b43d1ce1fd462fe2932f118c8cb3f385c6f37d0780de3ff22c918e22e632436a2cfd633b3d5a48a52fb31983477f0179248332ea94
7
+ data.tar.gz: a85c82617e04ee8a10f7f62df558b5e2c5a884e7c932ec8ce82fd6d3f6a9fe1008b4cd1908cec67f48f3612355dcb9577edfb13b0bb6736987603d2f75542964
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # rtiss_acts_as_versioned
2
+
3
+ This library adds simple versioning to an ActiveRecord module. ActiveRecord is required.
4
+
5
+ This is the patched version for rtiss.
6
+
7
+ Versions 0.9.x (master branch) are for Rails 4.x - 6.x
8
+ Versions 0.10.x (master branch) are for Rails >= 6.0 and Ruby >= 3.1.6
9
+
10
+ ### Resources
11
+
12
+ #### Install
13
+
14
+ `gem 'rtiss_acts_as_versioned', '0.10.1'`
15
+
16
+
17
+ #### GitHub
18
+
19
+ * http://github.com/technoweenie/acts_as_versioned
20
+
21
+ #### Rubygems
22
+
23
+ * https://rubygems.org/gems/rtiss_acts_as_versioned
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'rake'
3
3
  require 'date'
4
+ require 'rtiss_acts_as_versioned/version'
4
5
 
5
6
  #############################################################################
6
7
  #
@@ -13,8 +14,7 @@ def name
13
14
  end
14
15
 
15
16
  def version
16
- line = File.read("lib//#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
- line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
17
+ ActiveRecord::Acts::Versioned::VERSION
18
18
  end
19
19
 
20
20
  def date
@@ -122,11 +122,11 @@ task :gemspec => :validate do
122
122
  end
123
123
 
124
124
  task :validate do
125
- libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
126
- unless libfiles.empty?
127
- puts "Directory `lib` should only contain a `/#{name}.rb` file and `/#{name}` dir."
128
- exit!
129
- end
125
+ # libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
126
+ # unless libfiles.empty?
127
+ # puts "Directory `lib` should only contain a `/#{name}.rb` file and `/#{name}` dir."
128
+ # exit!
129
+ # end
130
130
  unless Dir['VERSION*'].empty?
131
131
  puts "A `VERSION` file at root level violates Gem best practices."
132
132
  exit!
data/init.rb CHANGED
@@ -1,2 +1,3 @@
1
- # encoding: utf-8
2
- require 'rtiss_acts_as_versioned'
1
+ Dir.glob(File.expand_path("lib/**/*.rb")).each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,289 @@
1
+ module ActiveRecord
2
+ module Acts
3
+ module Versioned
4
+ module ActMethods
5
+ def self.included(base) # :nodoc:
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ # Saves a version of the model in the versioned table. This is called in the after_save callback by default
10
+ def save_version(save_this=false, deleted_flag=false, restored_from_version=nil)
11
+ if @saving_version || save_this
12
+ @saving_version = nil
13
+ rev = self.class.versioned_class.new
14
+ clone_versioned_model(self, rev)
15
+ rev.send("#{self.class.version_column}=", send(self.class.version_column))
16
+ rev.send("#{self.class.versioned_foreign_key}=", id)
17
+ rev.send("#{self.class.deleted_in_original_table_flag}=", deleted_flag)
18
+ rev.send("#{self.class.record_restored_column}=", restored_from_version)
19
+ if rev.respond_to? :updated_at=
20
+ rev.updated_at = Time.now
21
+ end
22
+ rev.save
23
+ end
24
+ end
25
+
26
+ def set_deleted_flag
27
+ return if self.id.nil?
28
+
29
+ rev = self.class.versioned_class.new
30
+ clone_versioned_model(self, rev)
31
+ rev.send("#{self.class.version_column}=", highest_version+1)
32
+ rev.send("#{self.class.versioned_foreign_key}=", id)
33
+ rev.send("#{self.class.deleted_in_original_table_flag}=", true)
34
+ rev.send("#{self.class.record_restored_column}=", nil)
35
+ if rev.respond_to? :updated_at=
36
+ rev.updated_at = Time.now
37
+ end
38
+ rev.save
39
+ end
40
+
41
+ # Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
42
+ # Override this method to set your own criteria for clearing old versions.
43
+ def clear_old_versions
44
+ return if self.class.max_version_limit == 0
45
+ excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
46
+ if excess_baggage > 0
47
+ self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id]
48
+ end
49
+ end
50
+
51
+ # Reverts a model to a given version. Takes either a version number or an instance of the versioned model
52
+ def revert_to(version)
53
+ if version.is_a?(self.class.versioned_class)
54
+ @reverted_from = version.send(self.class.version_column)
55
+ return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
56
+ else
57
+ @reverted_from = version
58
+ version = versions.where(self.class.version_column => version).first
59
+ return false unless version
60
+ end
61
+ self.clone_versioned_model(version, self)
62
+ send("#{self.class.version_column}=", version.send(self.class.version_column))
63
+ true
64
+ end
65
+
66
+ # Reverts a model to a given version and saves the model.
67
+ # Takes either a version number or an instance of the versioned model
68
+ def revert_to!(version)
69
+ if revert_to(version)
70
+ set_new_version
71
+ save_without_revision
72
+ save_version(true, false, @reverted_from)
73
+ else
74
+ false
75
+ end
76
+ end
77
+
78
+ # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
79
+ def save_without_revision(perform_validation = true)
80
+ ret = false
81
+ without_locking do
82
+ without_revision do
83
+ ret = save(validate: perform_validation)
84
+ end
85
+ end
86
+ ret
87
+ end
88
+
89
+ def save_without_revision!
90
+ without_locking do
91
+ without_revision do
92
+ save!
93
+ end
94
+ end
95
+ end
96
+
97
+ def altered?
98
+ track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed?
99
+ end
100
+
101
+ # Clones a model. Used when saving a new version or reverting a model's version.
102
+ def clone_versioned_model(orig_model, new_model)
103
+ self.class.versioned_columns.each do |col|
104
+ new_model.send("#{col.name}=", orig_model.send(col.name)) if orig_model.has_attribute?(col.name)
105
+ end
106
+
107
+ clone_inheritance_column(orig_model, new_model)
108
+ end
109
+
110
+ def clone_inheritance_column(orig_model, new_model)
111
+ if orig_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(new_model.class.inheritance_column.to_s)
112
+ new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
113
+ elsif new_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(self.class.versioned_inheritance_column.to_s)
114
+ new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
115
+ end
116
+ end
117
+
118
+ # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
119
+ def save_version?
120
+ version_condition_met? && altered?
121
+ end
122
+
123
+ # Checks condition set in the :if option to check whether a revision should be created or not. Override this for
124
+ # custom version condition checking.
125
+ def version_condition_met?
126
+ case
127
+ when version_condition.is_a?(Symbol)
128
+ send(version_condition)
129
+ when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
130
+ version_condition.call(self)
131
+ else
132
+ version_condition
133
+ end
134
+ end
135
+
136
+ # Executes the block with the versioning callbacks disabled.
137
+ #
138
+ # @foo.without_revision do
139
+ # @foo.save
140
+ # end
141
+ #
142
+ def without_revision(&block)
143
+ self.class.without_revision(&block)
144
+ end
145
+
146
+ # Turns off optimistic locking for the duration of the block
147
+ #
148
+ # @foo.without_locking do
149
+ # @foo.save
150
+ # end
151
+ #
152
+ def without_locking(&block)
153
+ self.class.without_locking(&block)
154
+ end
155
+
156
+ def empty_callback() end #:nodoc:
157
+
158
+ def find_newest_version
159
+ return nil if self.id.nil?
160
+
161
+ self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id}").order("#{self.version_column} DESC").first
162
+ end
163
+
164
+ def highest_version
165
+ find_newest_version&.version || -1
166
+ end
167
+
168
+ def find_version(version)
169
+ return nil if self.id.nil?
170
+
171
+ ret = self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id} and #{self.class.version_column}=#{version}").first
172
+ raise "find_version: version #{version} not found in database" unless ret
173
+ ret
174
+ end
175
+
176
+ protected
177
+ # sets the new version before saving
178
+ def set_new_version
179
+ @saving_version = new_record? || save_version?
180
+ self.send("#{self.class.version_column}=", next_version) if new_record? || save_version?
181
+ end
182
+
183
+ # Gets the next available version for the current record, or 1 for a new record
184
+ def next_version
185
+ (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
186
+ end
187
+
188
+ module ClassMethods
189
+ # Returns an array of columns that are versioned. See non_versioned_columns
190
+ def versioned_columns
191
+ @versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) }
192
+ end
193
+
194
+ # Returns an instance of the dynamic versioned model
195
+ def versioned_class
196
+ const_get versioned_class_name
197
+ end
198
+
199
+ def restore_deleted(id)
200
+ version_record = versioned_class.where("#{versioned_foreign_key} = #{id}").order("#{self.version_column} DESC").first
201
+ version_record.restore
202
+ end
203
+
204
+ def restore_deleted_version(id, version)
205
+ version_record = versioned_class.where("#{versioned_foreign_key} = #{id} and #{self.version_column} = #{version}").first
206
+ version_record.restore
207
+ end
208
+
209
+ # Executes the block with the versioning callbacks disabled.
210
+ #
211
+ # Foo.without_revision do
212
+ # @foo.save
213
+ # end
214
+ #
215
+ def without_revision(&block)
216
+ class_eval do
217
+ CALLBACKS.each do |attr_name|
218
+ alias_method "orig_#{attr_name}".to_sym, attr_name
219
+ alias_method attr_name, :empty_callback
220
+ end
221
+ end
222
+ block.call
223
+ ensure
224
+ class_eval do
225
+ CALLBACKS.each do |attr_name|
226
+ alias_method attr_name, "orig_#{attr_name}".to_sym
227
+ end
228
+ end
229
+ end
230
+
231
+ # Turns off optimistic locking for the duration of the block
232
+ #
233
+ # Foo.without_locking do
234
+ # @foo.save
235
+ # end
236
+ #
237
+ def without_locking(&block)
238
+ current = ActiveRecord::Base.lock_optimistically
239
+ ActiveRecord::Base.lock_optimistically = false if current
240
+ begin
241
+ block.call
242
+ ensure
243
+ ActiveRecord::Base.lock_optimistically = true if current
244
+ end
245
+ end
246
+
247
+ # Rake migration task to create the versioned table using options passed to acts_as_versioned
248
+ def create_versioned_table(create_table_options = {})
249
+ # create version column in main table if it does not exist
250
+ unless self.column_names.find { |c| [version_column.to_s, 'lock_version'].include? c }
251
+ self.connection.add_column table_name, version_column, :integer
252
+ self.reset_column_information
253
+ end
254
+
255
+ return if connection.table_exists?(versioned_table_name)
256
+
257
+ self.connection.create_table(versioned_table_name, **create_table_options) do |t|
258
+ t.column versioned_foreign_key, :integer
259
+ t.column version_column, :integer
260
+ t.column deleted_in_original_table_flag, :boolean, default: false
261
+ t.column record_restored_column, :integer, default: nil
262
+ end
263
+
264
+ self.versioned_columns.each do |col|
265
+ self.connection.add_column versioned_table_name, col.name, col.type,
266
+ limit: col.limit,
267
+ default: col.default,
268
+ scale: col.scale,
269
+ precision: col.precision
270
+ end
271
+
272
+ if type_col = self.columns_hash[inheritance_column]
273
+ self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type,
274
+ limit: type_col.limit,
275
+ default: type_col.default,
276
+ scale: type_col.scale,
277
+ precision: type_col.precision
278
+ end
279
+ end
280
+
281
+ # Rake migration task to drop the versioned table
282
+ def drop_versioned_table
283
+ self.connection.drop_table versioned_table_name
284
+ end
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveRecord
2
+ module Acts
3
+ module Versioned
4
+ VERSION = '0.10.2'
5
+ end
6
+ end
7
+ end
@@ -20,7 +20,8 @@
20
20
  # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
 
23
- VERSION = '0.9.2'
23
+ require_relative './rtiss_acts_as_versioned/act_methods'
24
+ require_relative './rtiss_acts_as_versioned/version'
24
25
 
25
26
  module ActiveRecord #:nodoc:
26
27
  module Acts #:nodoc:
@@ -130,14 +131,14 @@ module ActiveRecord #:nodoc:
130
131
  #
131
132
  # == Database Schema
132
133
  #
133
- # The model that you're versioning needs to have a 'version' attribute. The model is versioned
134
- # into a table called #{model}_versions where the model name is singlular. The _versions table should
134
+ # The model that you're versioning needs to have a 'version' attribute. The model is versioned
135
+ # into a table called #{model}_versions where the model name is singlular. The _versions table should
135
136
  # contain all the fields you want versioned, the same version column, and a #{model}_id foreign key field.
136
137
  #
137
138
  # A lock_version field is also accepted if your model uses Optimistic Locking. If your table uses Single Table inheritance,
138
139
  # then that field is reflected in the versioned model as 'versioned_type' by default.
139
140
  #
140
- # Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table
141
+ # Acts_as_versioned comes prepared with the ActiveRecord::Acts::Versioned::ActMethods::ClassMethods#create_versioned_table
141
142
  # method, perfect for a migration. It will also create the version column if the main model does not already have it.
142
143
  #
143
144
  # class AddVersions < ActiveRecord::Migration
@@ -146,16 +147,16 @@ module ActiveRecord #:nodoc:
146
147
  # # that create_table does
147
148
  # Post.create_versioned_table
148
149
  # end
149
- #
150
+ #
150
151
  # def self.down
151
152
  # Post.drop_versioned_table
152
153
  # end
153
154
  # end
154
- #
155
+ #
155
156
  # == Changing What Fields Are Versioned
156
157
  #
157
- # By default, acts_as_versioned will version all but these fields:
158
- #
158
+ # By default, acts_as_versioned will version all but these fields:
159
+ #
159
160
  # [self.primary_key, inheritance_column, 'version', 'lock_version', versioned_inheritance_column]
160
161
  #
161
162
  # You can add or change those by modifying #non_versioned_columns. Note that this takes strings and not symbols.
@@ -164,7 +165,7 @@ module ActiveRecord #:nodoc:
164
165
  # acts_as_versioned
165
166
  # self.non_versioned_columns << 'comments_count'
166
167
  # end
167
- #
168
+ #
168
169
  def acts_as_versioned(options = {}, &extension)
169
170
  # don't allow multiple calls
170
171
  return if self.included_modules.include?(ActiveRecord::Acts::Versioned::ActMethods)
@@ -197,15 +198,11 @@ module ActiveRecord #:nodoc:
197
198
 
198
199
  if block_given?
199
200
  extension_module_name = "#{versioned_class_name}Extension"
200
- silence_warnings do
201
- self.const_set(extension_module_name, Module.new(&extension))
202
- end
203
-
204
201
  options[:extend] = self.const_get(extension_module_name)
205
202
  end
206
203
 
207
204
  class_eval <<-CLASS_METHODS, __FILE__, __LINE__ + 1
208
- has_many :versions, version_association_options do
205
+ has_many :versions, **version_association_options do
209
206
  # finds earliest version of this record
210
207
  def earliest
211
208
  @earliest ||= order('#{version_column}').first
@@ -234,14 +231,17 @@ module ActiveRecord #:nodoc:
234
231
  const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do
235
232
  def self.reloadable? ; false ; end
236
233
  # find first version before the given version
237
- # TODO: replace "version" in selects with version_column, use select-method instead of find
238
234
  def self.before(version)
239
- where("#{original_class.versioned_foreign_key} = ? and version < ?", version.send(original_class.versioned_foreign_key), version.version).order('version desc').first
235
+ where("#{original_class.versioned_foreign_key} = ? and #{self.version_column} < ?",
236
+ version.send(original_class.versioned_foreign_key), version.version)
237
+ .order("#{self.version_column} desc").first
240
238
  end
241
239
 
242
240
  # find first version after the given version.
243
241
  def self.after(version)
244
- where("#{original_class.versioned_foreign_key} = ? and version > ?", version.send(original_class.versioned_foreign_key), version.version).order('version').first
242
+ where("#{original_class.versioned_foreign_key} = ? and #{self.version_column} > ?",
243
+ version.send(original_class.versioned_foreign_key), version.version)
244
+ .order(self.version_column).first
245
245
  end
246
246
 
247
247
  def previous
@@ -252,10 +252,6 @@ module ActiveRecord #:nodoc:
252
252
  self.class.after(self)
253
253
  end
254
254
 
255
- def versions_count
256
- page.version # TODO: ?!
257
- end
258
-
259
255
  def restore(perform_validation = true)
260
256
  id = self.send(self.original_class.versioned_foreign_key)
261
257
  if self.original_class.exists?(id)
@@ -311,342 +307,8 @@ module ActiveRecord #:nodoc:
311
307
  versioned_class.sequence_name = version_sequence_name if version_sequence_name
312
308
  end
313
309
  end
314
-
315
- module ActMethods
316
- def self.included(base) # :nodoc:
317
- base.extend ClassMethods
318
- end
319
-
320
- # Saves a version of the model in the versioned table. This is called in the after_save callback by default
321
- def save_version(save_this=false, deleted_flag=false, restored_from_version=nil)
322
- if @saving_version || save_this
323
- @saving_version = nil
324
- rev = self.class.versioned_class.new
325
- clone_versioned_model(self, rev)
326
- rev.send("#{self.class.version_column}=", send(self.class.version_column))
327
- rev.send("#{self.class.versioned_foreign_key}=", id)
328
- rev.send("#{self.class.deleted_in_original_table_flag}=", deleted_flag)
329
- rev.send("#{self.class.record_restored_column}=", restored_from_version)
330
- if rev.respond_to? :updated_at=
331
- rev.updated_at = Time.now
332
- end
333
- rev.save
334
- end
335
- end
336
-
337
- def set_deleted_flag
338
- return if self.id.nil?
339
-
340
- rev = self.class.versioned_class.new
341
- clone_versioned_model(self, rev)
342
- rev.send("#{self.class.version_column}=", highest_version+1)
343
- rev.send("#{self.class.versioned_foreign_key}=", id)
344
- rev.send("#{self.class.deleted_in_original_table_flag}=", true)
345
- rev.send("#{self.class.record_restored_column}=", nil)
346
- if rev.respond_to? :updated_at=
347
- rev.updated_at = Time.now
348
- end
349
- rev.save
350
- end
351
-
352
- # Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
353
- # Override this method to set your own criteria for clearing old versions.
354
- def clear_old_versions
355
- return if self.class.max_version_limit == 0
356
- excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
357
- if excess_baggage > 0
358
- self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id]
359
- end
360
- end
361
-
362
- # Reverts a model to a given version. Takes either a version number or an instance of the versioned model
363
- def revert_to(version)
364
- if version.is_a?(self.class.versioned_class)
365
- @reverted_from = version.send(self.class.version_column)
366
- return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
367
- else
368
- @reverted_from = version
369
- version = versions.where(self.class.version_column => version).first
370
- return false unless version
371
- end
372
- self.clone_versioned_model(version, self)
373
- send("#{self.class.version_column}=", version.send(self.class.version_column))
374
- true
375
- end
376
-
377
- # Reverts a model to a given version and saves the model.
378
- # Takes either a version number or an instance of the versioned model
379
- def revert_to!(version)
380
- if revert_to(version)
381
- set_new_version
382
- save_without_revision
383
- save_version(true, false, @reverted_from)
384
- else
385
- false
386
- end
387
- end
388
-
389
- # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
390
- def save_without_revision(perform_validation = true)
391
- ret = false
392
- without_locking do
393
- without_revision do
394
- ret = save(:validate => perform_validation)
395
- end
396
- end
397
- return ret
398
- end
399
-
400
- def save_without_revision!
401
- without_locking do
402
- without_revision do
403
- save!
404
- end
405
- end
406
- end
407
-
408
- def altered?
409
- track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed?
410
- end
411
-
412
- # Clones a model. Used when saving a new version or reverting a model's version.
413
- def clone_versioned_model(orig_model, new_model)
414
- self.class.versioned_columns.each do |col|
415
- new_model.send("#{col.name}=", orig_model.send(col.name)) if orig_model.has_attribute?(col.name)
416
- end
417
-
418
- clone_inheritance_column(orig_model, new_model)
419
- end
420
-
421
- def clone_inheritance_column(orig_model, new_model)
422
- if orig_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(new_model.class.inheritance_column.to_s)
423
- new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
424
- elsif new_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(self.class.versioned_inheritance_column.to_s)
425
- new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
426
- end
427
- end
428
-
429
- # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
430
- def save_version?
431
- version_condition_met? && altered?
432
- end
433
-
434
- # Checks condition set in the :if option to check whether a revision should be created or not. Override this for
435
- # custom version condition checking.
436
- def version_condition_met?
437
- case
438
- when version_condition.is_a?(Symbol)
439
- send(version_condition)
440
- when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
441
- version_condition.call(self)
442
- else
443
- version_condition
444
- end
445
- end
446
-
447
- # Executes the block with the versioning callbacks disabled.
448
- #
449
- # @foo.without_revision do
450
- # @foo.save
451
- # end
452
- #
453
- def without_revision(&block)
454
- self.class.without_revision(&block)
455
- end
456
-
457
- # Turns off optimistic locking for the duration of the block
458
- #
459
- # @foo.without_locking do
460
- # @foo.save
461
- # end
462
- #
463
- def without_locking(&block)
464
- self.class.without_locking(&block)
465
- end
466
-
467
- def empty_callback() end #:nodoc:
468
-
469
- =begin
470
- # Alte finder-Syntax ab Rails 5 nicht mehr verwendbar.
471
- # Assoziation versions stattdessen verwenden
472
- def find_versions(*args)
473
- return [] if self.id.nil?
474
-
475
- options = args.extract_options!
476
- version_condition = "#{self.class.versioned_foreign_key} = #{self.id}"
477
- if options[:conditions]
478
- options[:conditions] += " and #{version_condition}"
479
- else
480
- options[:conditions] = version_condition
481
- end
482
- if args.first.is_a?(Symbol)
483
- versions.find(args.first, options)
484
- else # TODO: is_a?(Fixnum)
485
- versions.find(options)
486
- end
487
- end
488
- =end
489
-
490
- def find_newest_version
491
- return nil if self.id.nil?
492
-
493
- self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id}").order("version DESC").first
494
- end
495
-
496
- def highest_version
497
- v = find_newest_version
498
- if v then
499
- v.version
500
- else
501
- -1
502
- end
503
- end
504
-
505
- def find_version(version)
506
- return nil if self.id.nil?
507
-
508
- ret = self.class.versioned_class.where("#{self.class.versioned_foreign_key} = #{self.id} and #{self.class.version_column}=#{version}").first
509
- raise "find_version: version #{version} not found in database" unless ret
510
- ret
511
- end
512
-
513
- protected
514
- # sets the new version before saving
515
- def set_new_version
516
- @saving_version = new_record? || save_version?
517
- self.send("#{self.class.version_column}=", next_version) if new_record? || save_version?
518
- end
519
-
520
- # Gets the next available version for the current record, or 1 for a new record
521
- def next_version
522
- (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
523
- end
524
-
525
- module ClassMethods
526
- # Returns an array of columns that are versioned. See non_versioned_columns
527
- def versioned_columns
528
- @versioned_columns ||= columns.select { |c| !non_versioned_columns.include?(c.name) }
529
- end
530
-
531
- # Returns an instance of the dynamic versioned model
532
- def versioned_class
533
- const_get versioned_class_name
534
- end
535
-
536
- # Rake migration task to create the versioned table using options passed to acts_as_versioned
537
- def create_versioned_table(create_table_options = {})
538
- # create version column in main table if it does not exist
539
- if !self.content_columns.find { |c| [version_column.to_s, 'lock_version'].include? c.name }
540
- self.connection.add_column table_name, version_column, :integer
541
- self.reset_column_information
542
- end
543
-
544
- return if connection.table_exists?(versioned_table_name)
545
-
546
- self.connection.create_table(versioned_table_name, create_table_options) do |t|
547
- t.column versioned_foreign_key, :integer
548
- t.column version_column, :integer
549
- t.column deleted_in_original_table_flag, :boolean, :default => false
550
- t.column record_restored_column, :integer, :default => nil
551
- end
552
-
553
- self.versioned_columns.each do |col|
554
- self.connection.add_column versioned_table_name, col.name, col.type,
555
- :limit => col.limit,
556
- :default => col.default,
557
- :scale => col.scale,
558
- :precision => col.precision
559
- end
560
-
561
- if type_col = self.columns_hash[inheritance_column]
562
- self.connection.add_column versioned_table_name, versioned_inheritance_column, type_col.type,
563
- :limit => type_col.limit,
564
- :default => type_col.default,
565
- :scale => type_col.scale,
566
- :precision => type_col.precision
567
- end
568
-
569
- #self.connection.add_index versioned_table_name, versioned_foreign_key
570
- end
571
-
572
- # Rake migration task to drop the versioned table
573
- def drop_versioned_table
574
- self.connection.drop_table versioned_table_name
575
- end
576
-
577
- def restore_deleted(id)
578
- version_record = versioned_class.where("#{versioned_foreign_key} = #{id}").order("version DESC").first
579
- version_record.restore
580
- end
581
-
582
- def restore_deleted_version(id, version)
583
- version_record = versioned_class.where("#{versioned_foreign_key} = #{id} and version = #{version}").first
584
- version_record.restore
585
- end
586
-
587
- # Executes the block with the versioning callbacks disabled.
588
- #
589
- # Foo.without_revision do
590
- # @foo.save
591
- # end
592
- #
593
- def without_revision(&block)
594
- class_eval do
595
- CALLBACKS.each do |attr_name|
596
- alias_method "orig_#{attr_name}".to_sym, attr_name
597
- alias_method attr_name, :empty_callback
598
- end
599
- end
600
- block.call
601
- ensure
602
- class_eval do
603
- CALLBACKS.each do |attr_name|
604
- alias_method attr_name, "orig_#{attr_name}".to_sym
605
- end
606
- end
607
- end
608
-
609
- # Turns off optimistic locking for the duration of the block
610
- #
611
- # Foo.without_locking do
612
- # @foo.save
613
- # end
614
- #
615
- def without_locking(&block)
616
- current = ActiveRecord::Base.lock_optimistically
617
- ActiveRecord::Base.lock_optimistically = false if current
618
- begin
619
- block.call
620
- ensure
621
- ActiveRecord::Base.lock_optimistically = true if current
622
- end
623
- end
624
- end
625
- end
626
310
  end
627
311
  end
628
312
  end
629
313
 
630
- # TISS extension: do not pull this.
631
- module ActiveRecord #:nodoc:
632
- module ConnectionAdapters #:nodoc:
633
- class TableDefinition
634
- ## Erzeugt 4 Spalten created_at, updated_at, version, mutator_id die in
635
- ## jeder Daten-Tabelle notwendig sind. Verwendung:
636
- ## create_table :adresse do |t|
637
- ## t.standard_spalten
638
- ## t.string strasse, :size=>120
639
- ## t.string plz, :size=>4
640
- ## end
641
- def standard_spalten
642
- column(:created_at, :datetime)
643
- column(:updated_at, :datetime)
644
- column(:version, :integer, :default=>1)
645
- column(:mutator_id, :integer, :default=>0)
646
- end
647
- end
648
- end
649
- end
650
-
651
-
652
- ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned
314
+ ActiveRecord::Base.send :include, ActiveRecord::Acts::Versioned
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  ## If your rubyforge_project name is different, then edit it and comment out
13
13
  ## the sub! line in the Rakefile
14
14
  s.name = 'rtiss_acts_as_versioned'
15
- s.version = '0.9.2'
16
- s.date = '2020-04-27'
15
+ s.version = '0.10.2'
16
+ s.date = '2026-01-20'
17
17
  s.rubyforge_project = 'rtiss_acts_as_versioned'
18
18
  s.summary = "Add simple versioning to ActiveRecord models (TISS version)."
19
19
  s.description = "Add simple versioning to ActiveRecord models (TISS version).
@@ -29,27 +29,27 @@ to use technoweenie's version (can be found also on github)"
29
29
  s.homepage = 'http://github.com/rtiss/rtiss_acts_as_versioned'
30
30
  s.require_paths = ["lib"]
31
31
  s.rdoc_options = ["--charset=UTF-8"]
32
- s.extra_rdoc_files = %w[README MIT-LICENSE CHANGELOG]
32
+ s.extra_rdoc_files = %w[README.md MIT-LICENSE]
33
33
 
34
- s.add_dependency 'activerecord', ">= 4.2.5"
35
- s.add_development_dependency 'sqlite3-ruby', "~> 1.3.1"
36
- s.add_development_dependency 'rails', "~> 4.2.5"
34
+ s.add_dependency 'activerecord', ">= 7.1.6"
35
+ s.add_development_dependency 'sqlite3', '~> 2.7'
36
+ s.add_development_dependency 'rails', "~> 7.1.6"
37
37
  s.add_development_dependency 'activerecord-testcase'
38
- s.add_development_dependency 'activerecord-deprecated_finders' # todo alte, hash-basierte finders auf die neue AR Query-API migrieren
39
38
 
40
39
  ## Leave this section as-is. It will be automatically generated from the
41
40
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
42
41
  ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
43
42
  # = MANIFEST =
44
43
  s.files = %w[
45
- CHANGELOG
46
44
  Gemfile
47
45
  MIT-LICENSE
48
- README
46
+ README.md
49
47
  RUNNING_UNIT_TESTS
50
48
  Rakefile
51
49
  init.rb
52
50
  lib/rtiss_acts_as_versioned.rb
51
+ lib/rtiss_acts_as_versioned/act_methods.rb
52
+ lib/rtiss_acts_as_versioned/version.rb
53
53
  rtiss_acts_as_versioned.gemspec
54
54
  test/abstract_unit.rb
55
55
  test/database.yml
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtiss_acts_as_versioned
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Olson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-04-27 00:00:00.000000000 Z
13
+ date: 2026-01-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -18,42 +18,42 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 4.2.5
21
+ version: 7.1.6
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 4.2.5
28
+ version: 7.1.6
29
29
  - !ruby/object:Gem::Dependency
30
- name: sqlite3-ruby
30
+ name: sqlite3
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 1.3.1
35
+ version: '2.7'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 1.3.1
42
+ version: '2.7'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rails
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 4.2.5
49
+ version: 7.1.6
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 4.2.5
56
+ version: 7.1.6
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: activerecord-testcase
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -68,20 +68,6 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
- - !ruby/object:Gem::Dependency
72
- name: activerecord-deprecated_finders
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '0'
85
71
  description: "Add simple versioning to ActiveRecord models (TISS version).\n\nEach
86
72
  model has a to-many model named mymodel_h which records all changes \n(including
87
73
  destroys but not deletes) made to the model. This is the version\nused by http://tiss.tuwien.ac.at
@@ -92,18 +78,18 @@ email: igor.jancev@tuwien.ac.at
92
78
  executables: []
93
79
  extensions: []
94
80
  extra_rdoc_files:
95
- - README
81
+ - README.md
96
82
  - MIT-LICENSE
97
- - CHANGELOG
98
83
  files:
99
- - CHANGELOG
100
84
  - Gemfile
101
85
  - MIT-LICENSE
102
- - README
86
+ - README.md
103
87
  - RUNNING_UNIT_TESTS
104
88
  - Rakefile
105
89
  - init.rb
106
90
  - lib/rtiss_acts_as_versioned.rb
91
+ - lib/rtiss_acts_as_versioned/act_methods.rb
92
+ - lib/rtiss_acts_as_versioned/version.rb
107
93
  - rtiss_acts_as_versioned.gemspec
108
94
  - test/abstract_unit.rb
109
95
  - test/database.yml
@@ -143,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
129
  - !ruby/object:Gem::Version
144
130
  version: '0'
145
131
  requirements: []
146
- rubyforge_project: rtiss_acts_as_versioned
147
- rubygems_version: 2.6.14.4
132
+ rubygems_version: 3.3.27
148
133
  signing_key:
149
134
  specification_version: 4
150
135
  summary: Add simple versioning to ActiveRecord models (TISS version).
data/CHANGELOG DELETED
@@ -1,84 +0,0 @@
1
- *GIT* (version numbers are overrated)
2
-
3
- * 0.6 (19 Jul 2010) Rails 3 refactoring by gvarela!
4
-
5
- * (16 Jun 2008) Backwards Compatibility is overrated (big updates for rails 2.1)
6
-
7
- * Use ActiveRecord 2.1's dirty attribute checking instead [Asa Calow]
8
- * Remove last traces of #non_versioned_fields
9
- * Remove AR::Base.find_version and AR::Base.find_versions, rely on AR association proxies and named_scope
10
- * Remove #versions_count, rely on AR association counter caching.
11
- * Remove #versioned_attributes, basically the same as AR::Base.versioned_columns
12
-
13
- * (5 Oct 2006) Allow customization of #versions association options [Dan Peterson]
14
-
15
- *0.5.1*
16
-
17
- * (8 Aug 2006) Versioned models now belong to the unversioned model. @article_version.article.class => Article [Aslak Hellesoy]
18
-
19
- *0.5* # do versions even matter for plugins?
20
-
21
- * (21 Apr 2006) Added without_locking and without_revision methods.
22
-
23
- Foo.without_revision do
24
- @foo.update_attributes ...
25
- end
26
-
27
- *0.4*
28
-
29
- * (28 March 2006) Rename non_versioned_fields to non_versioned_columns (old one is kept for compatibility).
30
- * (28 March 2006) Made explicit documentation note that string column names are required for non_versioned_columns.
31
-
32
- *0.3.1*
33
-
34
- * (7 Jan 2006) explicitly set :foreign_key option for the versioned model's belongs_to assocation for STI [Caged]
35
- * (7 Jan 2006) added tests to prove has_many :through joins work
36
-
37
- *0.3*
38
-
39
- * (2 Jan 2006) added ability to share a mixin with versioned class
40
- * (2 Jan 2006) changed the dynamic version model to MyModel::Version
41
-
42
- *0.2.4*
43
-
44
- * (27 Nov 2005) added note about possible destructive behavior of if_changed? [Michael Schuerig]
45
-
46
- *0.2.3*
47
-
48
- * (12 Nov 2005) fixed bug with old behavior of #blank? [Michael Schuerig]
49
- * (12 Nov 2005) updated tests to use ActiveRecord Schema
50
-
51
- *0.2.2*
52
-
53
- * (3 Nov 2005) added documentation note to #acts_as_versioned [Martin Jul]
54
-
55
- *0.2.1*
56
-
57
- * (6 Oct 2005) renamed dirty? to changed? to keep it uniform. it was aliased to keep it backwards compatible.
58
-
59
- *0.2*
60
-
61
- * (6 Oct 2005) added find_versions and find_version class methods.
62
-
63
- * (6 Oct 2005) removed transaction from create_versioned_table().
64
- this way you can specify your own transaction around a group of operations.
65
-
66
- * (30 Sep 2005) fixed bug where find_versions() would order by 'version' twice. (found by Joe Clark)
67
-
68
- * (26 Sep 2005) added :sequence_name option to acts_as_versioned to set the sequence name on the versioned model
69
-
70
- *0.1.3* (18 Sep 2005)
71
-
72
- * First RubyForge release
73
-
74
- *0.1.2*
75
-
76
- * check if module is already included when acts_as_versioned is called
77
-
78
- *0.1.1*
79
-
80
- * Adding tests and rdocs
81
-
82
- *0.1*
83
-
84
- * Initial transfer from Rails ticket: http://dev.rubyonrails.com/ticket/1974
data/README DELETED
@@ -1,37 +0,0 @@
1
- = acts_as_versioned
2
-
3
- This library adds simple versioning to an ActiveRecord module. ActiveRecord is required.
4
-
5
- This is the patched version for rtiss.
6
-
7
- Versions 0.6.x (rails2 branch) are for rails 2.x
8
- Versions 0.7.x (rails3 branch) are for rails 3.x
9
- Versions 0.8.x (master branch) are for rails 4.x
10
- Versions 0.9.x (master branch) are for rails 5.x (also works with rails 4.x)
11
-
12
- == Resources
13
-
14
- Install
15
-
16
- * gem install acts_as_versioned
17
-
18
- <3 GitHub
19
-
20
- * http://github.com/technoweenie/acts_as_versioned
21
-
22
- Gemcutter FTW
23
-
24
- * http://gemcutter.org/gems/acts_as_versioned
25
-
26
- Subversion
27
-
28
- * http://svn.github.com/technoweenie/acts_as_versioned.git
29
-
30
- Special thanks to Dreamer on ##rubyonrails for help in early testing. His ServerSideWiki (http://serversidewiki.com)
31
- was the first project to use acts_as_versioned <em>in the wild</em>.
32
-
33
- == Publishing a new release
34
-
35
- * increase the VERSION in rtiss_acts_as_versioned.rb
36
- * run: bundle exec rake test
37
- * run: bundle exec rake release