sequel_paranoia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/sequel_paranoia.rb +83 -0
- data/lib/sequel_paranoia/version.rb +3 -0
- data/sequel_paranoia.gemspec +23 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmQ1NDQwMjk4NDczZDAwYzA4ZWZiZjE0YmI1ZjUxODUxOTRmNjA1NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTA2NmIxYTkyZWJlMWM1MTY4YWY5ZTJkYmIzZjA5MGU3ODkyNzA5ZA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTYwMDYzMGQ4YjdiY2M3MTY5OWY2NmIxMjhjMzlkOTdlYjBjNGYxYWQwMmY1
|
10
|
+
YWRlZmYxOWY4ZTZmMjVlNDFlMzFlMjBhZTViOTMwNzViOTczZGNjYzk5NjRh
|
11
|
+
NWYzN2Y2NjQ4MWE2YzZmY2RlZTdlMmYxYzk4Nzk4ZTY3NjcwNzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjBmOTIyNTYxODZmOTM0MDViZGIxNDg4YjhmMWRiZGYyYTVjMmViMmI0YzYy
|
14
|
+
Yjk0YjRjM2M0NjAzNWY5OGY0ZjYyNTQ3OGMwMWVlYzY0MDNjMTcwMjMzNWRj
|
15
|
+
ZjFhYjIxODI3MDQ3N2IxOTQzMWVkYjhhNzdkN2RiZTY3YTE3MzU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Misha Conway
|
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,29 @@
|
|
1
|
+
# SequelParanoia
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'sequel_paranoia'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install sequel_paranoia
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "sequel_paranoia/version"
|
2
|
+
|
3
|
+
module Sequel
|
4
|
+
module Plugins
|
5
|
+
# The paranoia plugin creates hooks that automatically set deleted
|
6
|
+
# timestamp fields. The field name used is configurable, and you
|
7
|
+
# can also set whether to overwrite existing deleted timestamps (false
|
8
|
+
# by default). Adapted from Timestamps plugin.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# # Soft deletion for all model instances using +deleted_at+
|
13
|
+
# # (called before loading subclasses)
|
14
|
+
# Sequel::Model.plugin :paranoia
|
15
|
+
#
|
16
|
+
# # Paranoid Album instances, with custom column names
|
17
|
+
# Album.plugin :paranoia, :deleted_at=>:deleted_time
|
18
|
+
#
|
19
|
+
# # Paranoid Artist instances, forcing an overwrite of the deleted
|
20
|
+
# # timestamp
|
21
|
+
# Album.plugin :paranoia, :force=>true
|
22
|
+
module Paranoia
|
23
|
+
# Configure the plugin by setting the avialable options. Note that
|
24
|
+
# if this method is run more than once, previous settings are ignored,
|
25
|
+
# and it will just use the settings given or the default settings. Options:
|
26
|
+
# * :deleted_at - The field to hold the deleted timestamp (default: :deleted_at)
|
27
|
+
# * :force - Whether to overwrite an existing deleted timestamp (default: false)
|
28
|
+
def self.configure(model, opts={})
|
29
|
+
model.instance_eval do
|
30
|
+
@deleted_timestamp_field = opts[:deleted_at]||:deleted_at
|
31
|
+
@deleted_timestamp_overwrite = opts[:force]||false
|
32
|
+
end
|
33
|
+
model.class_eval do
|
34
|
+
set_dataset filter("#{table_name}__#{@deleted_timestamp_field}".to_sym => nil)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
# The field to store the deleted timestamp
|
40
|
+
attr_reader :deleted_timestamp_field
|
41
|
+
|
42
|
+
# Whether to overwrite the deleted timestamp if it already exists
|
43
|
+
def deleted_timestamp_overwrite?
|
44
|
+
@deleted_timestamp_overwrite
|
45
|
+
end
|
46
|
+
|
47
|
+
# Copy the class instance variables used from the superclass to the subclass
|
48
|
+
def inherited(subclass)
|
49
|
+
super
|
50
|
+
[:@deleted_timestamp_field, :@deleted_timestamp_overwrite].each do |iv|
|
51
|
+
subclass.instance_variable_set(iv, instance_variable_get(iv))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def with_deleted
|
56
|
+
dataset.unfiltered
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module InstanceMethods
|
61
|
+
# Rather than delete the object, update its deleted timestamp field.
|
62
|
+
def delete
|
63
|
+
set_deleted_timestamp
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# If the object has accessor methods for the deleted timestamp field, and
|
69
|
+
# the deleted timestamp value is nil or overwriting it is allowed, set the
|
70
|
+
# deleted timestamp field to the time given or the current time.
|
71
|
+
def set_deleted_timestamp(time=nil)
|
72
|
+
field = model.deleted_timestamp_field
|
73
|
+
meth = :"#{field}="
|
74
|
+
if respond_to?(field) && respond_to?(meth) && (model.deleted_timestamp_overwrite? || send(field).nil?)
|
75
|
+
self.send(meth, time||=Sequel.datetime_class.now)
|
76
|
+
after_set_deleted_timestamp if respond_to? :after_set_deleted_timestamp
|
77
|
+
self.save
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sequel_paranoia/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sequel_paranoia"
|
8
|
+
spec.version = SequelParanoia::VERSION
|
9
|
+
spec.authors = ["Misha Conway"]
|
10
|
+
spec.email = ["MishaAConway@gmail.com"]
|
11
|
+
spec.description = %q{Works like ActiveRecord's acts_as_paranoid, but for sequel. I am not the original author of this plugin. I merely took the source, fixed one minor bug, and put it up on rubygems because I found it so useful. The original author is at https://gist.github.com/bgentry. }
|
12
|
+
spec.summary = %q{Works like ActiveRecord's acts_as_paranoid, but for sequel. I am not the original author of this plugin. I merely took the source, fixed one minor bug, and put it up on rubygems because I found it so useful. The original author is at https://gist.github.com/bgentry.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sequel_paranoia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Misha Conway
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.3'
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
description: ! 'Works like ActiveRecord''s acts_as_paranoid, but for sequel. I am
|
42
|
+
not the original author of this plugin. I merely took the source, fixed one minor
|
43
|
+
bug, and put it up on rubygems because I found it so useful. The original author
|
44
|
+
is at https://gist.github.com/bgentry. '
|
45
|
+
email:
|
46
|
+
- MishaAConway@gmail.com
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- .gitignore
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- lib/sequel_paranoia.rb
|
57
|
+
- lib/sequel_paranoia/version.rb
|
58
|
+
- sequel_paranoia.gemspec
|
59
|
+
homepage: ''
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.0.3
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Works like ActiveRecord's acts_as_paranoid, but for sequel. I am not the
|
83
|
+
original author of this plugin. I merely took the source, fixed one minor bug, and
|
84
|
+
put it up on rubygems because I found it so useful. The original author is at https://gist.github.com/bgentry.
|
85
|
+
test_files: []
|