cure_acts_as_versioned 0.6.1 → 0.6.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.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  group :development do
4
- gem 'rails', '3.0.0.beta4'
5
- gem 'sqlite3-ruby', '1.3.1'
6
- gem 'mysql', '2.8.1'
4
+ gem 'rails', '>=3.0.9'
5
+ gem 'sqlite3-ruby'
6
+ gem 'mysql'
7
7
  end
data/Rakefile CHANGED
@@ -60,7 +60,7 @@ task :coverage do
60
60
  sh "open coverage/index.html"
61
61
  end
62
62
 
63
- require 'rake/rdoctask'
63
+ require 'rdoc/task'
64
64
  Rake::RDocTask.new do |rdoc|
65
65
  rdoc.rdoc_dir = 'rdoc'
66
66
  rdoc.title = "#{name} #{version}"
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'cure_acts_as_versioned'
16
- s.version = '0.6.1'
17
- s.date = '2012-02-04'
16
+ s.version = '0.6.2'
17
+ s.date = '2014-01-26'
18
18
  s.rubyforge_project = 'acts_as_versioned'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -46,11 +46,11 @@ Gem::Specification.new do |s|
46
46
 
47
47
  ## List your runtime dependencies here. Runtime dependencies are those
48
48
  ## that are needed for an end user to actually USE your code.
49
- s.add_dependency('activerecord', ["~> 3.1"])
49
+ s.add_dependency('activerecord', [">= 3.0.9"])
50
50
 
51
51
  ## List your development dependencies here. Development dependencies are
52
52
  ## those that are only needed during development
53
- s.add_development_dependency('sqlite3-ruby', ["~> 1.3.1"])
53
+ s.add_development_dependency('sqlite3-ruby', [">= 1.3.1"])
54
54
 
55
55
  ## Leave this section as-is. It will be automatically generated from the
56
56
  ## contents of your Git repository via the gemspec task. DO NOT REMOVE
@@ -74,7 +74,7 @@ Gem::Specification.new do |s|
74
74
  test/fixtures/landmarks.yml
75
75
  test/fixtures/locked_pages.yml
76
76
  test/fixtures/locked_pages_revisions.yml
77
- test/fixtures/migrations/1_add_versioned_tables.rb
77
+ test/fixtures/migrations/2_add_versioned_tables.rb
78
78
  test/fixtures/page.rb
79
79
  test/fixtures/page_versions.yml
80
80
  test/fixtures/pages.yml
@@ -249,12 +249,12 @@ module ActiveRecord #:nodoc:
249
249
 
250
250
  versioned_class.cattr_accessor :original_class
251
251
  versioned_class.original_class = self
252
- versioned_class.set_table_name versioned_table_name
252
+ versioned_class.table_name = versioned_table_name
253
253
  versioned_class.belongs_to self.to_s.demodulize.underscore.to_sym,
254
254
  :class_name => "::#{self.to_s}",
255
255
  :foreign_key => versioned_foreign_key
256
256
  versioned_class.send :include, options[:extend] if options[:extend].is_a?(Module)
257
- versioned_class.set_sequence_name version_sequence_name if version_sequence_name
257
+ versioned_class.sequence_name = version_sequence_name if version_sequence_name
258
258
  end
259
259
 
260
260
  module Behaviors
@@ -268,134 +268,136 @@ module ActiveRecord #:nodoc:
268
268
  after_save :clear_old_versions
269
269
  end
270
270
 
271
- module InstanceMethods
272
- # Saves a version of the model in the versioned table. This is called in the after_save callback by default
273
- def save_version
274
- if @saving_version
275
- @saving_version = nil
276
- rev = self.class.versioned_class.new
277
- clone_versioned_model(self, rev)
278
- rev.send("#{self.class.version_column}=", send(self.class.version_column))
279
- rev.send("#{self.class.versioned_foreign_key}=", id)
280
- rev.save
281
- end
271
+ # Saves a version of the model in the versioned table. This is called in the after_save callback by default
272
+ def save_version
273
+ if @saving_version
274
+ @saving_version = nil
275
+ rev = self.class.versioned_class.new
276
+ clone_versioned_model(self, rev)
277
+ rev.send("#{self.class.version_column}=", send(self.class.version_column))
278
+ rev.send("#{self.class.versioned_foreign_key}=", id)
279
+ rev.save
282
280
  end
281
+ end
283
282
 
284
- # Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
285
- # Override this method to set your own criteria for clearing old versions.
286
- def clear_old_versions
287
- return if self.class.max_version_limit == 0
288
- excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
289
- if excess_baggage > 0
290
- self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id]
291
- end
283
+ # Clears old revisions if a limit is set with the :limit option in <tt>acts_as_versioned</tt>.
284
+ # Override this method to set your own criteria for clearing old versions.
285
+ def clear_old_versions
286
+ return if self.class.max_version_limit == 0
287
+ excess_baggage = send(self.class.version_column).to_i - self.class.max_version_limit
288
+ if excess_baggage > 0
289
+ self.class.versioned_class.delete_all ["#{self.class.version_column} <= ? and #{self.class.versioned_foreign_key} = ?", excess_baggage, id]
292
290
  end
291
+ end
293
292
 
294
- # Reverts a model to a given version. Takes either a version number or an instance of the versioned model
295
- def revert_to(version)
296
- if version.is_a?(self.class.versioned_class)
297
- return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
298
- else
299
- return false unless version = versions.where(self.class.version_column => version).first
300
- end
301
- self.clone_versioned_model(version, self)
302
- send("#{self.class.version_column}=", version.send(self.class.version_column))
303
- true
293
+ # Reverts a model to a given version. Takes either a version number or an instance of the versioned model
294
+ def revert_to(version)
295
+ if version.is_a?(self.class.versioned_class)
296
+ return false unless version.send(self.class.versioned_foreign_key) == id and !version.new_record?
297
+ else
298
+ return false unless version = versions.where(self.class.version_column => version).first
304
299
  end
300
+ self.clone_versioned_model(version, self)
301
+ send("#{self.class.version_column}=", version.send(self.class.version_column))
302
+ true
303
+ end
305
304
 
306
- # Reverts a model to a given version and saves the model.
307
- # Takes either a version number or an instance of the versioned model
308
- def revert_to!(version)
309
- revert_to(version) ? save_without_revision : false
310
- end
305
+ # Reverts a model to a given version and saves the model.
306
+ # Takes either a version number or an instance of the versioned model
307
+ def revert_to!(version)
308
+ revert_to(version) ? save_without_revision : false
309
+ end
311
310
 
312
- # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
313
- def save_without_revision
314
- save_without_revision!
315
- true
316
- rescue
317
- false
318
- end
311
+ # Temporarily turns off Optimistic Locking while saving. Used when reverting so that a new version is not created.
312
+ def save_without_revision
313
+ save_without_revision!
314
+ true
315
+ rescue
316
+ false
317
+ end
319
318
 
320
- def save_without_revision!
321
- without_locking do
322
- without_revision do
323
- save!
324
- end
319
+ def save_without_revision!
320
+ without_locking do
321
+ without_revision do
322
+ save!
325
323
  end
326
324
  end
325
+ end
327
326
 
328
- def altered?
329
- track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed?
330
- end
331
-
332
- # Clones a model. Used when saving a new version or reverting a model's version.
333
- def clone_versioned_model(orig_model, new_model)
334
- self.class.versioned_columns.each do |col|
335
- new_model[col.name] = orig_model.send(col.name) if orig_model.has_attribute?(col.name)
336
- end
327
+ def altered?
328
+ track_altered_attributes ? (version_if_changed - changed).length < version_if_changed.length : changed?
329
+ end
337
330
 
338
- if orig_model.is_a?(self.class.versioned_class)
339
- new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
340
- elsif new_model.is_a?(self.class.versioned_class)
341
- new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
342
- end
331
+ # Clones a model. Used when saving a new version or reverting a model's version.
332
+ def clone_versioned_model(orig_model, new_model)
333
+ self.class.versioned_columns.each do |col|
334
+ new_model[col.name] = orig_model.send(col.name) if orig_model.has_attribute?(col.name)
343
335
  end
344
336
 
345
- # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
346
- def save_version?
347
- version_condition_met? && altered?
337
+ clone_inheritance_column(orig_model, new_model)
338
+ end
339
+
340
+ def clone_inheritance_column(orig_model, new_model)
341
+ if orig_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(new_model.class.inheritance_column.to_s)
342
+ new_model[new_model.class.inheritance_column] = orig_model[self.class.versioned_inheritance_column]
343
+ elsif new_model.is_a?(self.class.versioned_class) && new_model.class.column_names.include?(self.class.versioned_inheritance_column.to_s)
344
+ new_model[self.class.versioned_inheritance_column] = orig_model[orig_model.class.inheritance_column]
348
345
  end
346
+ end
349
347
 
350
- # Checks condition set in the :if option to check whether a revision should be created or not. Override this for
351
- # custom version condition checking.
352
- def version_condition_met?
353
- case
354
- when version_condition.is_a?(Symbol)
355
- send(version_condition)
356
- when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
357
- version_condition.call(self)
358
- else
359
- version_condition
360
- end
361
- end
348
+ # Checks whether a new version shall be saved or not. Calls <tt>version_condition_met?</tt> and <tt>changed?</tt>.
349
+ def save_version?
350
+ version_condition_met? && altered?
351
+ end
362
352
 
363
- # Executes the block with the versioning callbacks disabled.
364
- #
365
- # @foo.without_revision do
366
- # @foo.save
367
- # end
368
- #
369
- def without_revision(&block)
370
- self.class.without_revision(&block)
353
+ # Checks condition set in the :if option to check whether a revision should be created or not. Override this for
354
+ # custom version condition checking.
355
+ def version_condition_met?
356
+ case
357
+ when version_condition.is_a?(Symbol)
358
+ send(version_condition)
359
+ when version_condition.respond_to?(:call) && (version_condition.arity == 1 || version_condition.arity == -1)
360
+ version_condition.call(self)
361
+ else
362
+ version_condition
371
363
  end
364
+ end
372
365
 
373
- # Turns off optimistic locking for the duration of the block
374
- #
375
- # @foo.without_locking do
376
- # @foo.save
377
- # end
378
- #
379
- def without_locking(&block)
380
- self.class.without_locking(&block)
381
- end
366
+ # Executes the block with the versioning callbacks disabled.
367
+ #
368
+ # @foo.without_revision do
369
+ # @foo.save
370
+ # end
371
+ #
372
+ def without_revision(&block)
373
+ self.class.without_revision(&block)
374
+ end
382
375
 
383
- def empty_callback()
384
- end
376
+ # Turns off optimistic locking for the duration of the block
377
+ #
378
+ # @foo.without_locking do
379
+ # @foo.save
380
+ # end
381
+ #
382
+ def without_locking(&block)
383
+ self.class.without_locking(&block)
384
+ end
385
385
 
386
- #:nodoc:
386
+ def empty_callback()
387
+ end
387
388
 
388
- protected
389
- # sets the new version before saving, unless you're using optimistic locking. In that case, let it take care of the version.
390
- def set_new_version
391
- @saving_version = new_record? || save_version?
392
- self.send("#{self.class.version_column}=", next_version) if new_record? || (!locking_enabled? && save_version?)
393
- end
389
+ #:nodoc:
394
390
 
395
- # Gets the next available version for the current record, or 1 for a new record
396
- def next_version
397
- (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
398
- end
391
+ protected
392
+ # sets the new version before saving, unless you're using optimistic locking. In that case, let it take care of the version.
393
+ def set_new_version
394
+ @saving_version = new_record? || save_version?
395
+ self.send("#{self.class.version_column}=", next_version) if new_record? || (!locking_enabled? && save_version?)
396
+ end
397
+
398
+ # Gets the next available version for the current record, or 1 for a new record
399
+ def next_version
400
+ (new_record? ? 0 : versions.calculate(:maximum, version_column).to_i) + 1
399
401
  end
400
402
 
401
403
  module ClassMethods
@@ -19,7 +19,6 @@ if ActiveRecord::Base.connection.supports_migrations?
19
19
 
20
20
  Thing.connection.drop_table "things" rescue nil
21
21
  Thing.connection.drop_table "thing_versions" rescue nil
22
- Thing.reset_column_information
23
22
  end
24
23
 
25
24
  def test_versioned_migration
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cure_acts_as_versioned
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ward Vandewege
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-04 00:00:00 -05:00
19
- default_executable:
18
+ date: 2014-01-26 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: activerecord
@@ -24,13 +23,14 @@ dependencies:
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
27
- - - ~>
26
+ - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 5
28
+ hash: 21
30
29
  segments:
31
30
  - 3
32
- - 1
33
- version: "3.1"
31
+ - 0
32
+ - 9
33
+ version: 3.0.9
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
36
  - !ruby/object:Gem::Dependency
@@ -39,7 +39,7 @@ dependencies:
39
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  hash: 25
45
45
  segments:
@@ -77,7 +77,7 @@ files:
77
77
  - test/fixtures/landmarks.yml
78
78
  - test/fixtures/locked_pages.yml
79
79
  - test/fixtures/locked_pages_revisions.yml
80
- - test/fixtures/migrations/1_add_versioned_tables.rb
80
+ - test/fixtures/migrations/2_add_versioned_tables.rb
81
81
  - test/fixtures/page.rb
82
82
  - test/fixtures/page_versions.yml
83
83
  - test/fixtures/pages.yml
@@ -85,7 +85,6 @@ files:
85
85
  - test/migration_test.rb
86
86
  - test/schema.rb
87
87
  - test/versioned_test.rb
88
- has_rdoc: true
89
88
  homepage: http://github.com/cure/acts_as_versioned
90
89
  licenses: []
91
90
 
@@ -115,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
114
  requirements: []
116
115
 
117
116
  rubyforge_project: acts_as_versioned
118
- rubygems_version: 1.5.2
117
+ rubygems_version: 1.8.24
119
118
  signing_key:
120
119
  specification_version: 2
121
120
  summary: Add simple versioning to ActiveRecord models.