has_archive 0.4.5 → 0.5.0
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 +4 -4
- data/LICENSE +21 -0
- data/README.md +1 -0
- data/has_archive.gemspec +1 -0
- data/lib/has_archive.rb +12 -4
- data/lib/has_archive/railtie.rb +0 -3
- data/lib/has_archive/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b05410cd8cd3f1fb33fce456d0ece2a050c416f6
|
|
4
|
+
data.tar.gz: 2656a77a95e4449a147b56c4a4a937cb24bf42d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 81516d4e018ba909d5dfbac1c0087eecdfa5597e16495a94469dcf285a632f462df017a9e318f5dd9c0cb3274e2716a8a537395afa1a10c26977aa75cbfbce89
|
|
7
|
+
data.tar.gz: 3a3cdc29f6537d1bbefdf91bf8a6b54e72b252ef2b1c776328dfdac42b1d8afbae0fdbf3f34d03408e141a4ed3e218cbeb870743127700e86564ea3ff79fa89f
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Matt Morris
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
This project was born out of frustration with all the options I've found so far for archiving non-current ActiveRecord backed models, so I'm going to give it a go. The initial target will be Rails 4 (point two-ish) on Postgres, and if it goes somewhere, I will begin looking at what else we can support.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/rb/has_archive)
|
|
6
|
+
[](https://codeclimate.com/github/matt-morris/has_archive)
|
|
6
7
|
|
|
7
8
|
Please halp. This is far from ready, but if this seems like a useful/worthwhile project to you, please feel free to dig and lend a hand.
|
|
8
9
|
|
data/has_archive.gemspec
CHANGED
|
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.summary = %q{Add archives to your ActiveRecord models}
|
|
13
13
|
spec.description = %q{Add archives to your ActiveRecord models}
|
|
14
14
|
spec.homepage = "http://github.com/matt-morris/has_archive"
|
|
15
|
+
spec.licenses = ["MIT"]
|
|
15
16
|
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
17
18
|
spec.bindir = "exe"
|
data/lib/has_archive.rb
CHANGED
|
@@ -7,7 +7,7 @@ module HasArchive
|
|
|
7
7
|
base.send :extend, ClassMethods
|
|
8
8
|
base.send :include, InstanceMethods
|
|
9
9
|
|
|
10
|
-
eval <<-
|
|
10
|
+
eval <<-RUBY
|
|
11
11
|
class #{base}::Archive < #{base}
|
|
12
12
|
self.table_name = "#{base.to_s.underscore}_archives"
|
|
13
13
|
|
|
@@ -19,7 +19,7 @@ module HasArchive
|
|
|
19
19
|
self
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
|
-
|
|
22
|
+
RUBY
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
module ClassMethods
|
|
@@ -30,14 +30,22 @@ module HasArchive
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
module InstanceMethods
|
|
33
|
-
def archive
|
|
33
|
+
def archive(force: false)
|
|
34
34
|
archive = self.class::Archive.new(self.attributes)
|
|
35
35
|
archive.archived_at = Time.now
|
|
36
36
|
archive.save(validate: false)
|
|
37
37
|
self.destroy(for_real: true)
|
|
38
|
+
rescue ActiveRecord::RecordNotUnique => e
|
|
39
|
+
if force
|
|
40
|
+
self.class::Archive.find(archive.id).destroy(for_real: true)
|
|
41
|
+
self.archive
|
|
42
|
+
else
|
|
43
|
+
Rails.logger.warn "Rescued attempt to archive record with existing key: #{archive.id}."
|
|
44
|
+
false
|
|
45
|
+
end
|
|
38
46
|
end
|
|
39
47
|
|
|
40
|
-
def destroy(for_real: false)
|
|
48
|
+
def destroy(for_real: false, force: false)
|
|
41
49
|
if !for_real && Rails.configuration.has_archive.override_destroy
|
|
42
50
|
archive
|
|
43
51
|
else
|
data/lib/has_archive/railtie.rb
CHANGED
|
@@ -2,9 +2,6 @@ module HasArchive
|
|
|
2
2
|
class Railtie < Rails::Railtie
|
|
3
3
|
initializer "railtie.configure_rails_initialization" do #|app|
|
|
4
4
|
# TODO is there actually anything we need to do with an initializer?
|
|
5
|
-
puts "///////////////////////////////////////////////////////////////////////////////////////////////"
|
|
6
|
-
puts "////// initializing has_archive ///////////////////////////////////////////////////////////////"
|
|
7
|
-
puts "///////////////////////////////////////////////////////////////////////////////////////////////"
|
|
8
5
|
end
|
|
9
6
|
|
|
10
7
|
# TODO is this where we want to pass in initialization options?
|
data/lib/has_archive/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: has_archive
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matt Morris
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- ".rspec"
|
|
64
64
|
- ".travis.yml"
|
|
65
65
|
- Gemfile
|
|
66
|
+
- LICENSE
|
|
66
67
|
- README.md
|
|
67
68
|
- Rakefile
|
|
68
69
|
- bin/console
|
|
@@ -75,7 +76,8 @@ files:
|
|
|
75
76
|
- lib/has_archive/railtie.rb
|
|
76
77
|
- lib/has_archive/version.rb
|
|
77
78
|
homepage: http://github.com/matt-morris/has_archive
|
|
78
|
-
licenses:
|
|
79
|
+
licenses:
|
|
80
|
+
- MIT
|
|
79
81
|
metadata: {}
|
|
80
82
|
post_install_message:
|
|
81
83
|
rdoc_options: []
|
|
@@ -93,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
93
95
|
version: '0'
|
|
94
96
|
requirements: []
|
|
95
97
|
rubyforge_project:
|
|
96
|
-
rubygems_version: 2.
|
|
98
|
+
rubygems_version: 2.5.1
|
|
97
99
|
signing_key:
|
|
98
100
|
specification_version: 4
|
|
99
101
|
summary: Add archives to your ActiveRecord models
|