mongomapper-archive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/lib/archive_document.rb +3 -0
- data/lib/mongomapper/archive.rb +29 -0
- data/lib/mongomapper/archive/version.rb +5 -0
- data/mongomapper-archive.gemspec +22 -0
- data/spec/archive_spec.rb +15 -0
- data/spec/spec_helper.rb +22 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 218274fec9194eccbbe1b8538965debdde162836
|
4
|
+
data.tar.gz: a2f71f5932d07b4ae3ee4b3820f8ca5f48a2307f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e271cf71152fa6a6d8ee6ea00cfcc9a7e76f213de46af4584d0ee61b53ec9a7e765ca2ce4d695e5868e43d26de0d186c28393c53855f159c6b956c3fdfa68fff
|
7
|
+
data.tar.gz: 6afcc687a33c7b848e9230be41224f4a7c4d88d19e5dfbc15182ba36b688aa16cf69f44850684ca25c60dca6f67a11d7dd8899e6642f02a94585e1038d6d0f6e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 DivShot
|
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,40 @@
|
|
1
|
+
# Mongomapper::Archive
|
2
|
+
|
3
|
+
MongoMapper::Archive (Archive for short) is a plugin for [MongoMapper](http://mongomapper.com/) that adds simple archiving functionality to your models.
|
4
|
+
|
5
|
+
Archive doesn't rely on a default scope, only applies to the models you specify, and only hooks into the `before_destroy` callback. It's as unobtrusive as it can be.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'mongomapper-archive'
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install mongomapper-archive
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
Add it to a model:
|
20
|
+
```
|
21
|
+
class Post
|
22
|
+
include MongoMapper::Document
|
23
|
+
plugin MongoMapper::Archive
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
After that, any call to `destroy` a document of this class will first copy the document to a separate collection, *then* destroy the document.
|
28
|
+
|
29
|
+
## Limitations
|
30
|
+
|
31
|
+
* Archive does not currently provide a means to recover archived documents.
|
32
|
+
* Archive adds an `ArchiveDocument` collection to your database.
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
1. Fork it
|
37
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
38
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
39
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "archive_document"
|
2
|
+
require "mongomapper/archive/version"
|
3
|
+
|
4
|
+
module Mongomapper
|
5
|
+
module Archive
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
before_destroy :archive
|
10
|
+
|
11
|
+
@archive = create_archive_class
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def create_archive_class
|
16
|
+
archive_class_name = :"Archive#{self.name}"
|
17
|
+
const_set(archive_class_name, Class.new(ArchiveDocument)) unless const_defined?(archive_class_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def archive
|
21
|
+
@archive
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def archive
|
26
|
+
self.class.archive.create(self.to_mongo)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mongomapper/archive/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mongomapper-archive"
|
8
|
+
spec.version = Mongomapper::Archive::VERSION
|
9
|
+
spec.authors = ["Ben Scofield"]
|
10
|
+
spec.email = ["git@turrean.com"]
|
11
|
+
spec.description = "Add simple archive / soft delete functionality to your MongoMapper models."
|
12
|
+
spec.summary = "Add simple archive / soft delete functionality to your MongoMapper models."
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_runtime_dependency "mongo_mapper", ">= 0.12.0"
|
20
|
+
spec.add_development_dependency "rspec", "~> 2.13.0"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mongomapper::Archive do
|
4
|
+
context 'destroy' do
|
5
|
+
let!(:journal) { Journal.create(title: "My big adventure", body: "I had the *best* day...") }
|
6
|
+
|
7
|
+
it 'should copy the journal to the archive collection' do
|
8
|
+
expect{ journal.destroy }.to change(Journal.archive, :count).by(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should still destroy the journal' do
|
12
|
+
expect{ journal.destroy }.to change(Journal, :count).by(-1)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rspec'
|
5
|
+
require 'mongo_mapper'
|
6
|
+
require 'mongomapper/archive'
|
7
|
+
|
8
|
+
MongoMapper.database = 'archive-spec'
|
9
|
+
|
10
|
+
class Journal
|
11
|
+
include MongoMapper::Document
|
12
|
+
plugin Mongomapper::Archive
|
13
|
+
|
14
|
+
key :title, String
|
15
|
+
key :body, String
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.before :suite do
|
20
|
+
MongoMapper.database.connection.drop_database('archive-spec')
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongomapper-archive
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Scofield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mongo_mapper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.12.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.12.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Add simple archive / soft delete functionality to your MongoMapper models.
|
56
|
+
email:
|
57
|
+
- git@turrean.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/archive_document.rb
|
68
|
+
- lib/mongomapper/archive.rb
|
69
|
+
- lib/mongomapper/archive/version.rb
|
70
|
+
- mongomapper-archive.gemspec
|
71
|
+
- spec/archive_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
73
|
+
homepage:
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Add simple archive / soft delete functionality to your MongoMapper models.
|
97
|
+
test_files:
|
98
|
+
- spec/archive_spec.rb
|
99
|
+
- spec/spec_helper.rb
|