acts_as_archive 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -13
- data/Rakefile +2 -49
- data/bin/acts_as_archive +1 -2
- data/lib/acts_as_archive/base.rb +0 -15
- data/lib/acts_as_archive.rb +16 -2
- data/rails/init.rb +3 -2
- data/require.rb +47 -0
- data/spec/spec_helper.rb +3 -17
- metadata +13 -3
data/README.markdown
CHANGED
@@ -5,16 +5,11 @@ Don't delete your records, move them to a different table.
|
|
5
5
|
|
6
6
|
Like <code>acts\_as\_paranoid</code>, but doesn't mess with your SQL queries.
|
7
7
|
|
8
|
-
Compatibility
|
9
|
-
-------------
|
10
|
-
|
11
|
-
Tested with Ruby 1.8.6, 1.8.7, and 1.9.1.
|
12
|
-
|
13
8
|
Install
|
14
9
|
-------
|
15
10
|
|
16
11
|
<pre>
|
17
|
-
sudo gem install acts_as_archive
|
12
|
+
sudo gem install acts_as_archive
|
18
13
|
</pre>
|
19
14
|
|
20
15
|
**environment.rb**:
|
@@ -39,19 +34,17 @@ end
|
|
39
34
|
Run acts\_as\_archive
|
40
35
|
---------------------
|
41
36
|
|
42
|
-
Terminal:
|
43
|
-
|
44
37
|
<pre>
|
45
38
|
cd your_rails_app
|
46
39
|
acts_as_archive Article
|
47
40
|
</pre>
|
48
41
|
|
42
|
+
Run this command every time you add <code>acts\_as\_archive</code> to a new model.
|
43
|
+
|
49
44
|
This command creates your archive tables (<code>archived_articles</code> as per the example).
|
50
45
|
|
51
46
|
Archive tables mirror your table's structure, but with an additional <code>deleted_at</code> column.
|
52
47
|
|
53
|
-
Run this command every time you add <code>acts\_as\_archive</code> to a new model.
|
54
|
-
|
55
48
|
That's it!
|
56
49
|
----------
|
57
50
|
|
@@ -62,7 +55,7 @@ Records move into the archive table instead of being destroyed.
|
|
62
55
|
What if my schema changes?
|
63
56
|
--------------------------
|
64
57
|
|
65
|
-
|
58
|
+
New migrations are automatically applied to the archive table.
|
66
59
|
|
67
60
|
Query the archive
|
68
61
|
-----------------
|
@@ -85,7 +78,7 @@ Article.restore_all([ 'id = ?', 1 ])
|
|
85
78
|
Auto-migrate from acts\_as\_paranoid
|
86
79
|
------------------------------------
|
87
80
|
|
88
|
-
If you previously used <code>acts\_as\_paranoid</code>,
|
81
|
+
If you previously used <code>acts\_as\_paranoid</code>, the <code>acts\_as\_archive</code>
|
89
82
|
command will automatically move your deleted records to the archive table
|
90
83
|
(see <a href="#run_acts_as_archive">_Run acts\_as\_archive_</a>).
|
91
84
|
|
@@ -104,5 +97,5 @@ class Article < ActiveRecord::Base
|
|
104
97
|
end
|
105
98
|
</pre>
|
106
99
|
|
107
|
-
Run the <code>acts\_as\_archive</code> command
|
100
|
+
Run the <code>acts\_as\_archive</code> command upon adding new indexes
|
108
101
|
(see <a href="#run_acts_as_archive">_Run acts\_as\_archive_</a>).
|
data/Rakefile
CHANGED
@@ -1,49 +1,2 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'rake/gempackagetask'
|
4
|
-
require 'spec/rake/spectask'
|
5
|
-
|
6
|
-
GEM_NAME = 'acts_as_archive'
|
7
|
-
PKG_FILES = FileList['**/*'] - FileList['coverage', 'coverage/**/*', 'pkg', 'pkg/**/*', 'spec/db/log/*.log']
|
8
|
-
|
9
|
-
spec = Gem::Specification.new do |s|
|
10
|
-
s.author = "Winton Welsh"
|
11
|
-
s.email = "mail@wintoni.us"
|
12
|
-
s.executables << GEM_NAME
|
13
|
-
s.extra_rdoc_files = [ "README.markdown" ]
|
14
|
-
s.files = PKG_FILES.to_a
|
15
|
-
s.homepage = "http://github.com/winton/#{GEM_NAME}"
|
16
|
-
s.name = GEM_NAME
|
17
|
-
s.platform = Gem::Platform::RUBY
|
18
|
-
s.require_path = "lib"
|
19
|
-
s.summary = "Don't delete your records, move them to a different table"
|
20
|
-
s.version = "0.1.6"
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "Package gem"
|
24
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
25
|
-
pkg.gem_spec = spec
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "Install gem"
|
29
|
-
task :install do
|
30
|
-
Rake::Task['gem'].invoke
|
31
|
-
`gem uninstall #{GEM_NAME} -x`
|
32
|
-
`gem install pkg/#{GEM_NAME}*.gem`
|
33
|
-
`rm -Rf pkg`
|
34
|
-
end
|
35
|
-
|
36
|
-
desc "Generate gemspec"
|
37
|
-
task :gemspec do
|
38
|
-
File.open("#{File.dirname(__FILE__)}/#{GEM_NAME}.gemspec", 'w') do |f|
|
39
|
-
f.write(spec.to_ruby)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "Run specs"
|
44
|
-
Spec::Rake::SpecTask.new do |t|
|
45
|
-
t.spec_opts = ["--format", "specdoc", "--colour"]
|
46
|
-
t.spec_files = FileList["spec/**/*_spec.rb"]
|
47
|
-
end
|
48
|
-
|
49
|
-
task :default => :spec
|
1
|
+
require "#{File.dirname(__FILE__)}/require"
|
2
|
+
Require.rakefile!
|
data/bin/acts_as_archive
CHANGED
data/lib/acts_as_archive/base.rb
CHANGED
@@ -1,20 +1,5 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/base/destroy"
|
2
|
-
require File.dirname(__FILE__) + "/base/restore"
|
3
|
-
require File.dirname(__FILE__) + "/base/table"
|
4
|
-
|
5
1
|
module ActsAsArchive
|
6
2
|
|
7
|
-
def self.update(*models)
|
8
|
-
models.each do |klass|
|
9
|
-
if klass.respond_to?(:acts_as_archive?) && klass.acts_as_archive?
|
10
|
-
klass.create_archive_table
|
11
|
-
klass.migrate_from_acts_as_paranoid
|
12
|
-
klass.create_archive_indexes
|
13
|
-
puts 'Success!'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
3
|
module Base
|
19
4
|
def self.included(base)
|
20
5
|
base.extend ActMethods
|
data/lib/acts_as_archive.rb
CHANGED
@@ -1,2 +1,16 @@
|
|
1
|
-
require File.dirname(__FILE__)
|
2
|
-
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../require")
|
2
|
+
Require.lib!
|
3
|
+
|
4
|
+
module ActsAsArchive
|
5
|
+
|
6
|
+
def self.update(*models)
|
7
|
+
models.each do |klass|
|
8
|
+
if klass.respond_to?(:acts_as_archive?) && klass.acts_as_archive?
|
9
|
+
klass.create_archive_table
|
10
|
+
klass.migrate_from_acts_as_paranoid
|
11
|
+
klass.create_archive_indexes
|
12
|
+
puts 'Success!'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/rails/init.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__)
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../require")
|
2
|
+
Require.rails_init!
|
2
3
|
|
3
4
|
ActiveRecord::Base.send(:include, ActsAsArchive::Base)
|
4
|
-
ActiveRecord::Migration.send(:include, ActsAsArchive::Migration)
|
5
|
+
ActiveRecord::Migration.send(:include, ActsAsArchive::Migration)
|
data/require.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'require'
|
3
|
+
require 'require'
|
4
|
+
|
5
|
+
Require File.dirname(__FILE__) do
|
6
|
+
gem(:activerecord) { require 'active_record' }
|
7
|
+
gem :require, '=0.1.8'
|
8
|
+
gem(:rake, '=0.8.7') { require 'rake' }
|
9
|
+
gem :rspec, '=1.3.0'
|
10
|
+
|
11
|
+
gemspec do
|
12
|
+
author 'Winton Welsh'
|
13
|
+
dependencies do
|
14
|
+
gem :require
|
15
|
+
end
|
16
|
+
email 'mail@wintoni.us'
|
17
|
+
name 'acts_as_archive'
|
18
|
+
homepage "http://github.com/winton/#{name}"
|
19
|
+
summary "Don't delete your records, move them to a different table"
|
20
|
+
version '0.2.0'
|
21
|
+
end
|
22
|
+
|
23
|
+
lib do
|
24
|
+
require "lib/acts_as_archive/base"
|
25
|
+
require "lib/acts_as_archive/base/destroy"
|
26
|
+
require "lib/acts_as_archive/base/restore"
|
27
|
+
require "lib/acts_as_archive/base/table"
|
28
|
+
require "lib/acts_as_archive/migration"
|
29
|
+
end
|
30
|
+
|
31
|
+
rails_init { require 'lib/acts_as_archive' }
|
32
|
+
|
33
|
+
rakefile do
|
34
|
+
gem(:rake) { require 'rake/gempackagetask' }
|
35
|
+
gem(:rspec) { require 'spec/rake/spectask' }
|
36
|
+
require 'require/tasks'
|
37
|
+
end
|
38
|
+
|
39
|
+
spec_helper do
|
40
|
+
require 'require/spec_helper'
|
41
|
+
gem :activerecord
|
42
|
+
require 'logger'
|
43
|
+
require 'yaml'
|
44
|
+
require 'pp'
|
45
|
+
require 'rails/init'
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'active_record'
|
6
|
-
require 'logger'
|
7
|
-
require 'yaml'
|
8
|
-
require 'pp'
|
9
|
-
|
10
|
-
require File.expand_path("#{SPEC}/../rails/init")
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../require")
|
2
|
+
Require.spec_helper!
|
11
3
|
|
12
4
|
Spec::Runner.configure do |config|
|
13
5
|
end
|
@@ -54,12 +46,6 @@ def create_records(klass=Article, values={})
|
|
54
46
|
end
|
55
47
|
end
|
56
48
|
|
57
|
-
def debug(object)
|
58
|
-
puts "<pre>"
|
59
|
-
pp object
|
60
|
-
puts "</pre>"
|
61
|
-
end
|
62
|
-
|
63
49
|
def establish_test_db
|
64
50
|
# Establish connection
|
65
51
|
unless ActiveRecord::Base.connected?
|
@@ -97,4 +83,4 @@ def migrate_up(directory='migrate')
|
|
97
83
|
ActiveRecord::Migrator.migrate("#{SPEC}/db/#{directory}")
|
98
84
|
@new_article_columns = columns("articles")
|
99
85
|
@new_archive_columns = columns("archived_articles")
|
100
|
-
end
|
86
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_archive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Winton Welsh
|
@@ -11,8 +11,17 @@ cert_chain: []
|
|
11
11
|
|
12
12
|
date: 2010-02-03 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: require
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - "="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.8
|
24
|
+
version:
|
16
25
|
description:
|
17
26
|
email: mail@wintoni.us
|
18
27
|
executables:
|
@@ -34,6 +43,7 @@ files:
|
|
34
43
|
- rails/init.rb
|
35
44
|
- Rakefile
|
36
45
|
- README.markdown
|
46
|
+
- require.rb
|
37
47
|
- spec/acts_as_archive/base/destroy_spec.rb
|
38
48
|
- spec/acts_as_archive/base/restore_spec.rb
|
39
49
|
- spec/acts_as_archive/base/table_spec.rb
|