mongoid-archivable 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/lib/mongoid/archivable/version.rb +1 -1
- data/lib/mongoid/archivable.rb +10 -10
- data/mongoid-archivable.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9957577e624c1560404e6435b9713fa24ea54048
|
4
|
+
data.tar.gz: 2a85513a462e58eaaf81aac60b5074f363914d9b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: accc81a71d53bf7e5443ae99a3809593c5f3de4c448f8d800c49d1e7c2b709f146b109039f414b6d5799dcbabbe14bbfb0fd5fb5ed453827586f7f0ad987514e
|
7
|
+
data.tar.gz: 595a05d2b0e70e6934b0163a61b41f147f152facf670acc781e60f7140d61965dd91a497d3edf8220cfb6d6c34e6c9dbb62465a700f8ca4332466d6821950712
|
data/LICENSE.txt
CHANGED
data/lib/mongoid/archivable.rb
CHANGED
@@ -2,7 +2,6 @@ require 'active_support/concern'
|
|
2
2
|
|
3
3
|
module Mongoid
|
4
4
|
module Archivable
|
5
|
-
|
6
5
|
extend ActiveSupport::Concern
|
7
6
|
|
8
7
|
module Restoration
|
@@ -13,8 +12,9 @@ module Mongoid
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def original_document
|
16
|
-
|
17
|
-
|
15
|
+
excluded_attributes = %i(_id original_id original_type archived_at)
|
16
|
+
original_class_name.constantize.new(attributes.except(*excluded_attributes)) do |doc|
|
17
|
+
doc.id = original_id
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -22,8 +22,8 @@ module Mongoid
|
|
22
22
|
# since previous versions of this gem did not use this field, fall back
|
23
23
|
# to previous method -- removing the '::Archive' from archive class name
|
24
24
|
def original_class_name
|
25
|
-
if
|
26
|
-
|
25
|
+
if respond_to?(:original_type) && original_type.present? # gem version >= 1.3.0, stored as a field.
|
26
|
+
original_type
|
27
27
|
else
|
28
28
|
self.class.to_s.gsub(/::Archive\z/, '') # gem version < 1.3.0, turns "User::Archive" into "User".
|
29
29
|
end
|
@@ -31,11 +31,12 @@ module Mongoid
|
|
31
31
|
end
|
32
32
|
|
33
33
|
included do
|
34
|
-
|
35
|
-
|
34
|
+
const_set('Archive', Class.new)
|
35
|
+
const_get('Archive').class_eval do
|
36
36
|
include Mongoid::Document
|
37
37
|
include Mongoid::Attributes::Dynamic
|
38
38
|
include Mongoid::Archivable::Restoration
|
39
|
+
|
39
40
|
field :archived_at, type: Time
|
40
41
|
field :original_id, type: String
|
41
42
|
field :original_type, type: String
|
@@ -47,12 +48,11 @@ module Mongoid
|
|
47
48
|
private
|
48
49
|
|
49
50
|
def archive
|
50
|
-
self.class.const_get(
|
51
|
-
doc.original_id =
|
51
|
+
self.class.const_get('Archive').create(attributes.except('_id', '_type')) do |doc|
|
52
|
+
doc.original_id = id
|
52
53
|
doc.original_type = self.class.to_s
|
53
54
|
doc.archived_at = Time.now.utc
|
54
55
|
end
|
55
56
|
end
|
56
|
-
|
57
57
|
end
|
58
58
|
end
|
data/mongoid-archivable.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "mongoid"
|
22
|
+
spec.add_dependency "mongoid", "~> 5.0"
|
23
23
|
spec.add_dependency "activesupport", ">= 4.0.0"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler"
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-archivable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joost Baaij
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|