undestroy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +92 -0
- data/Rakefile +7 -0
- data/lib/undestroy.rb +5 -0
- data/lib/undestroy/version.rb +3 -0
- data/test/helper.rb +2 -0
- data/test/unit/undestroy_test.rb +10 -0
- data/undestroy.gemspec +22 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Travis Petticrew
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Undestroy
|
2
|
+
|
3
|
+
Allow copying records to alternate table before destroying an
|
4
|
+
ActiveRecord model for archiving purposes. Data will be mapped
|
5
|
+
one-to-one to the archive table schema. Additional fields can also be
|
6
|
+
configured for additional tracking information. Archive table schema
|
7
|
+
will automatically be updated when the parent model's table is migrated
|
8
|
+
through Rails.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'undestroy'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install undestroy
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
To activate Undestroy on a model, simply call the `undestroyable` method
|
27
|
+
on the class like so:
|
28
|
+
|
29
|
+
class Person < ActiveRecord::Base
|
30
|
+
undestroyable
|
31
|
+
end
|
32
|
+
|
33
|
+
This method also can accept an options hash to further customize
|
34
|
+
Undestroy to your needs.
|
35
|
+
|
36
|
+
* `:table_name`: use this table for archiving
|
37
|
+
* `:class_name`: use this AR model for archiving
|
38
|
+
* `:connection`: use this connection for archiving
|
39
|
+
* `:fields`: Specify a hash of fields to values for additional fields
|
40
|
+
you would like to include on the archive table -- lambdas will be
|
41
|
+
called with the instance being destroyed and returned value will be
|
42
|
+
used (default: `{ :deleted_at => proc { |instance| Time.now } }`).
|
43
|
+
* `:migrate`: Should Undestroy migrate the archive table together with
|
44
|
+
this model's table (default: true)
|
45
|
+
|
46
|
+
$ person = Person.find(1)
|
47
|
+
$ person.destroy
|
48
|
+
# => Inserts person data into archive_people table
|
49
|
+
# => Deletes person data from people table
|
50
|
+
|
51
|
+
## Stucture
|
52
|
+
|
53
|
+
This is the basic class structure of this gem. It was designed to be
|
54
|
+
modular and easy to tailor to your specific needs.
|
55
|
+
|
56
|
+
### `Archive`
|
57
|
+
|
58
|
+
Map the source model's schema to the archive model's and initiate the
|
59
|
+
transfer through `Transfer`. When `run` is called the Transfer is
|
60
|
+
initialized with a primitive hash mapping the schema to the archive
|
61
|
+
table.
|
62
|
+
|
63
|
+
Initialized with:
|
64
|
+
|
65
|
+
* `:config`: Instance of Undestroy::Config for this model
|
66
|
+
* `:source`: Instance of the source model
|
67
|
+
|
68
|
+
### `Restore`
|
69
|
+
|
70
|
+
Map the archive model's schema to the source model's and initiate the
|
71
|
+
transfer through `Transfer`
|
72
|
+
|
73
|
+
Initialized with:
|
74
|
+
|
75
|
+
* `:config`: Instance of Undestroy::Config for this model
|
76
|
+
* `:archive`: Instance of the archived model
|
77
|
+
|
78
|
+
### `Transfer`
|
79
|
+
|
80
|
+
Handles the actual movement of data from one table to another. This
|
81
|
+
class simply uses the AR interface to create and delete the appropriate
|
82
|
+
records. This can be subclassed to provide enhanced performance or
|
83
|
+
customized behavior for your situation.
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
1. Fork it
|
88
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
89
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
90
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
91
|
+
5. Create new Pull Request
|
92
|
+
|
data/Rakefile
ADDED
data/lib/undestroy.rb
ADDED
data/test/helper.rb
ADDED
data/undestroy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/undestroy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Travis Petticrew"]
|
6
|
+
gem.email = ["bobo@petticrew.net"]
|
7
|
+
gem.description = %q{Move AR records to alternate table on destroy and allow restoring.}
|
8
|
+
gem.summary = %q{Allow AR records to be undestroyed by archiving their data in a seperate table when destroying the original data}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "undestroy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Undestroy::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'activerecord', '~>3.0'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'assert', '~>0.7'
|
21
|
+
gem.add_development_dependency 'assert-rails', '~>0.2'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: undestroy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Travis Petticrew
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-03-12 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: "3.0"
|
33
|
+
name: activerecord
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 5
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 7
|
47
|
+
version: "0.7"
|
48
|
+
name: assert
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 15
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
- 2
|
62
|
+
version: "0.2"
|
63
|
+
name: assert-rails
|
64
|
+
version_requirements: *id003
|
65
|
+
description: Move AR records to alternate table on destroy and allow restoring.
|
66
|
+
email:
|
67
|
+
- bobo@petticrew.net
|
68
|
+
executables: []
|
69
|
+
|
70
|
+
extensions: []
|
71
|
+
|
72
|
+
extra_rdoc_files: []
|
73
|
+
|
74
|
+
files:
|
75
|
+
- .gitignore
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/undestroy.rb
|
81
|
+
- lib/undestroy/version.rb
|
82
|
+
- test/helper.rb
|
83
|
+
- test/unit/undestroy_test.rb
|
84
|
+
- undestroy.gemspec
|
85
|
+
homepage: ""
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
hash: 3
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
requirements: []
|
112
|
+
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.17
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Allow AR records to be undestroyed by archiving their data in a seperate table when destroying the original data
|
118
|
+
test_files:
|
119
|
+
- test/helper.rb
|
120
|
+
- test/unit/undestroy_test.rb
|