mongoid-archivable 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5d3c5c5b690a5f2b6d113ac0ce5a76c3ae127c8
4
- data.tar.gz: 4670145aace8e5f856be1bb33997b3ef096b466e
3
+ metadata.gz: c887499fc91768e2d5545a2c6dbf439e08885e2c
4
+ data.tar.gz: 895ff222f43ed6753a1f7ad0e1c9be176ff0c15e
5
5
  SHA512:
6
- metadata.gz: 67483355fd3743415f9de3b31d22e7dfd0162ce418a4da9d5df647fa9a28d0db24efb2fd25fb687e29d6bf07fea1b7ab39b4da0a6751d4cfeaa69e0c47615541
7
- data.tar.gz: ff304197b3a196c1c2549b3c58549832ad7de27adfd932f6b90d17b6363de66c1bf16feaf8ad4bd6faa2811ecfd3e2a22408cbd0a957f9a75aa21b7174dd1801
6
+ metadata.gz: 9ad8ecb9ba0cf5b05bea72627f93075af85f9d3a152efc5df806b6fced2dfe369fd654f43d228f78338d7fd9155eb76a320ae9b538dd02101cb74edd1e4e364c
7
+ data.tar.gz: c569029340b31e767cdab0cd24e2b0e3610baa80ed2001e3ff8276865545658202bf5c5b60cecede36b80cb417878c3bd83df4f2639861a9b5b121939e4fd3df
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.4
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Moves Mongoid documents to an archive instead of destroying them.
4
4
 
5
+ [ ![Codeship Status for Sign2Pay/mongoid-archivable](https://codeship.com/projects/a6d39180-c4c7-0132-bf85-1a3509ce6b71/status?branch=master)](https://codeship.com/projects/74192)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -28,6 +30,8 @@ include Mongoid::Archivable
28
30
 
29
31
  Now a `destroy` of a document will move the document to an Archive collection, namespaced under the document you're destroying.
30
32
 
33
+ You can restore an archive as well. Send the `.restore` message to it. For now the archived document is retained, but that might change in the future.
34
+
31
35
  ## Example
32
36
 
33
37
  ```
@@ -36,6 +40,12 @@ user.destroy
36
40
 
37
41
  User.count # => 0
38
42
  User::Archive.count # => 1
43
+
44
+ archived_user = User::Archive.last
45
+ archived_user.restore
46
+
47
+ User.count # => 1
48
+ User::Archive.count # => 1
39
49
  ```
40
50
 
41
51
  ## Development
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Archivable
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,14 +1,27 @@
1
- require "mongoid/archivable/version"
1
+ require 'active_support/concern'
2
2
 
3
3
  module Mongoid
4
4
  module Archivable
5
5
 
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ module Restoration
9
+ # Restores the archived document to its former glory.
10
+ def restore
11
+ document = self.class.to_s.split('::').first # Turns User::Archive into User.
12
+
13
+ self.class.const_get(document).create(attributes.except("_id", "original_id", "archived_at")) do |doc|
14
+ doc.id = self.original_id
15
+ end
16
+ end
17
+ end
18
+
8
19
  included do
9
20
  self.const_set("Archive", Class.new)
10
- self.const_get("Archive").send(:include, ::Mongoid::Document).class_eval do
21
+ self.const_get("Archive").class_eval do
22
+ include Mongoid::Document
11
23
  include Mongoid::Attributes::Dynamic
24
+ include Mongoid::Archivable::Restoration
12
25
  field :archived_at, type: Time
13
26
  field :original_id, type: String
14
27
  end
@@ -1 +1,2 @@
1
+ require "mongoid/archivable/version"
1
2
  require 'mongoid/archivable'
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "mongoid"
23
23
  spec.add_dependency "activesupport", ">= 4.0.0"
24
24
 
25
- spec.add_development_dependency "bundler", "~> 1.9"
26
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec", "~> 3.2.0"
27
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-archivable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -42,30 +42,44 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.9'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.9'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '10.0'
75
+ version: 3.2.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '10.0'
82
+ version: 3.2.0
69
83
  description: Move Mongoid documents to an archive instead of destroying them.
70
84
  email:
71
85
  - joost@spacebabies.nl
@@ -75,6 +89,7 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
92
+ - ".ruby-version"
78
93
  - CODE_OF_CONDUCT.md
79
94
  - Gemfile
80
95
  - LICENSE.txt