abbish_sequel_plugins 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +15 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +72 -0
- data/Rakefile +10 -0
- data/abbish_sequel_plugins.gemspec +19 -0
- data/lib/abbish_sequel_plugins.rb +1 -1
- data/lib/model/record_timestamp.rb +2 -6
- data/lib/model/record_version.rb +2 -5
- data/spec/lib/model.rb +20 -0
- data/spec/record_protection_spec.rb +37 -0
- data/spec/record_timestamp_spec.rb +32 -0
- data/spec/record_version_spec.rb +38 -0
- metadata +69 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 853e613c24a604f65481ea72bb0eb1901830006c
|
4
|
+
data.tar.gz: 011fb670c37f13cb9bec898dd7605de31a179542
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a64a2e60b10087b94727989cfe3f515490d96c303dc78082bc83be68e8fc83c26b362c1b98d2194eb867b510651e4e8615889ab58ce7b2aa2395c738a2fd7d0
|
7
|
+
data.tar.gz: 7b3cf541678cd9067a3228364d5190597cfab186e1528c1eb376c1ab7d36a3bfc9566da09b89e86b39234b1e349ed7df00719c311194f01579008bfe6d1a7455
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 abbish
|
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,72 @@
|
|
1
|
+
# abbish_sequel_plugins
|
2
|
+
|
3
|
+
Frequently used plugins for Sequel
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'abbish_sequel_plugins'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install abbish_sequel_plugins
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
###RecordProtection
|
24
|
+
```ruby
|
25
|
+
class Model < Sequel::Model(:test_table)
|
26
|
+
plugin Abbish::Sequel::Plugins::Model::RecordProtection, { options }
|
27
|
+
end
|
28
|
+
```
|
29
|
+
Default options
|
30
|
+
```ruby
|
31
|
+
{
|
32
|
+
:enabled => true,
|
33
|
+
:column_protected => :record_protected,
|
34
|
+
:raise_protected_message => 'Cannot destroy protected record'
|
35
|
+
}
|
36
|
+
```
|
37
|
+
======
|
38
|
+
###RecordTimestamp
|
39
|
+
```ruby
|
40
|
+
class Model < Sequel::Model(:test_table)
|
41
|
+
plugin Abbish::Sequel::Plugins::Model::RecordTimestamp { options }
|
42
|
+
end
|
43
|
+
```
|
44
|
+
Default options
|
45
|
+
```ruby
|
46
|
+
{
|
47
|
+
:enabled => true,
|
48
|
+
:column_created_time => :record_created_time,
|
49
|
+
:column_updated_time => :record_updated_time
|
50
|
+
}
|
51
|
+
```
|
52
|
+
======
|
53
|
+
###RecordVersion
|
54
|
+
```ruby
|
55
|
+
class Model < Sequel::Model(:test_table)
|
56
|
+
plugin Abbish::Sequel::Plugins::Model::RecordVersion
|
57
|
+
end
|
58
|
+
```
|
59
|
+
Default options
|
60
|
+
```ruby
|
61
|
+
{
|
62
|
+
:enabled => true,
|
63
|
+
:column_version => :record_version
|
64
|
+
}
|
65
|
+
```
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
1. Fork it ( https://github.com/abbish/abbish_sequel_plugins/fork )
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/lib/abbish_sequel_plugins'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'abbish_sequel_plugins'
|
6
|
+
spec.version = Abbish::Sequel::Plugins::Version
|
7
|
+
spec.authors = ['abbish']
|
8
|
+
spec.email = ['me@abbish.com']
|
9
|
+
spec.summary = %q{Frequently used plugins for Sequel}
|
10
|
+
spec.description = %q{For more detail please visit https://github.com/abbish/abbish_sequel_plugins}
|
11
|
+
spec.homepage = 'https://github.com/abbish/abbish-sequel-plugins'
|
12
|
+
spec.licenses = ['MIT']
|
13
|
+
spec.require_paths = %w(lib lib/model)
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.add_development_dependency "minitest"
|
16
|
+
spec.add_development_dependency "rake"
|
17
|
+
spec.add_development_dependency "sequel"
|
18
|
+
spec.add_development_dependency "sqlite3"
|
19
|
+
end
|
@@ -28,17 +28,13 @@ module Abbish
|
|
28
28
|
module InstanceMethods
|
29
29
|
|
30
30
|
def before_create
|
31
|
-
super
|
32
31
|
self.record_created_time = _get_time if self.class.record_timestamp_options[:enabled]
|
32
|
+
super
|
33
33
|
end
|
34
34
|
|
35
35
|
def before_update
|
36
|
+
self.record_updated_time = _get_time if self.class.record_timestamp_options[:enabled] if self.modified?
|
36
37
|
super
|
37
|
-
if self.modified?
|
38
|
-
self.record_updated_time = _get_time if self.class.record_timestamp_options[:enabled]
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
38
|
end
|
43
39
|
|
44
40
|
private
|
data/lib/model/record_version.rb
CHANGED
@@ -27,16 +27,13 @@ module Abbish
|
|
27
27
|
module InstanceMethods
|
28
28
|
|
29
29
|
def before_create
|
30
|
-
super
|
31
30
|
self.record_version = _get_version if self.class.record_version_options[:enabled]
|
32
|
-
|
31
|
+
super
|
33
32
|
end
|
34
33
|
|
35
34
|
def before_update
|
35
|
+
self.record_version = _get_version if self.class.record_version_options[:enabled] if self.modified?
|
36
36
|
super
|
37
|
-
if self.modified?
|
38
|
-
self.record_version = _get_version if self.class.record_version_options[:enabled]
|
39
|
-
end
|
40
37
|
end
|
41
38
|
|
42
39
|
private
|
data/spec/lib/model.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'abbish_sequel_plugins'
|
3
|
+
|
4
|
+
Sequel::Model.db = Sequel.sqlite
|
5
|
+
Sequel::Model.db.create_table :test_table do
|
6
|
+
primary_key :id
|
7
|
+
String :table_field
|
8
|
+
String :record_version
|
9
|
+
Time :record_created_time
|
10
|
+
Time :record_updated_time
|
11
|
+
Time :record_deleted_time
|
12
|
+
Integer :record_protected
|
13
|
+
Integer :record_deleted
|
14
|
+
end
|
15
|
+
|
16
|
+
class Model < Sequel::Model(:test_table)
|
17
|
+
plugin Abbish::Sequel::Plugins::Model::RecordProtection
|
18
|
+
plugin Abbish::Sequel::Plugins::Model::RecordTimestamp
|
19
|
+
plugin Abbish::Sequel::Plugins::Model::RecordVersion
|
20
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require File.dirname(__FILE__) + '/lib/model'
|
3
|
+
|
4
|
+
describe 'RecordProtectionSpec' do
|
5
|
+
describe 'record protection' do
|
6
|
+
before do
|
7
|
+
@model = Model.create(:table_field => 'test')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should has method to set record protection' do
|
11
|
+
defined?(@model.record_protected?).wont_be_nil
|
12
|
+
defined?(@model.set_record_protected).wont_be_nil
|
13
|
+
defined?(@model.set_record_protected!).wont_be_nil
|
14
|
+
|
15
|
+
@model.record_protected?.must_equal false
|
16
|
+
|
17
|
+
@model.set_record_protected
|
18
|
+
|
19
|
+
@model.record_protected?.must_equal true
|
20
|
+
|
21
|
+
model = Model[@model.id]
|
22
|
+
model.record_protected?.must_equal false
|
23
|
+
|
24
|
+
@model.set_record_protected!
|
25
|
+
|
26
|
+
model = Model[@model.id]
|
27
|
+
model.record_protected?.must_equal true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should has error when destroy a protected record' do
|
31
|
+
@model.set_record_protected!
|
32
|
+
|
33
|
+
model = Model[@model.id]
|
34
|
+
proc { model.destroy }.must_raise Abbish::Sequel::Plugins::Model::RecordProtectedError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require File.dirname(__FILE__) + '/lib/model'
|
3
|
+
|
4
|
+
describe 'RecordTimestampSpec' do
|
5
|
+
describe 'record timestamp' do
|
6
|
+
before do
|
7
|
+
@model = Model.create(:table_field => 'test')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should has time in record_created_time when record created' do
|
11
|
+
@model.record_created_time.wont_be_nil
|
12
|
+
@model.record_updated_time.must_be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should has time in record_updated_time when record updated' do
|
16
|
+
@model.record_updated_time.must_be_nil
|
17
|
+
|
18
|
+
@model.table_field = 'updated'
|
19
|
+
@model.save
|
20
|
+
|
21
|
+
@model.record_updated_time.wont_be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should has different record_updated_time when record updated' do
|
25
|
+
new_model = Model[@model.id]
|
26
|
+
new_model.table_field = 'updated'
|
27
|
+
new_model.save
|
28
|
+
|
29
|
+
@model.record_updated_time.wont_equal new_model.record_updated_time
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require File.dirname(__FILE__) + '/lib/model'
|
3
|
+
|
4
|
+
describe 'RecordVersionSpec' do
|
5
|
+
describe 'record version' do
|
6
|
+
before do
|
7
|
+
@model = Model.create(:table_field => 'test')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should has md5 format version in record_version when record created' do
|
11
|
+
@model.record_version.wont_be_nil
|
12
|
+
@model.record_version.size.must_equal 32
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should has md5 format version in record_version when record created' do
|
16
|
+
new_model = Model[@model.id]
|
17
|
+
new_model.table_field = 'updated'
|
18
|
+
new_model.save
|
19
|
+
|
20
|
+
@model.record_version.wont_equal new_model.record_version
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should not update version when record was not modified' do
|
24
|
+
new_model = Model[@model.id]
|
25
|
+
new_model.save
|
26
|
+
|
27
|
+
@model.record_version.must_equal new_model.record_version
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should has different version when record was updated' do
|
31
|
+
new_model = Model[@model.id]
|
32
|
+
new_model.table_field = 'updated'
|
33
|
+
new_model.save
|
34
|
+
|
35
|
+
@model.record_version.wont_equal new_model.record_version
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abbish_sequel_plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abbish
|
@@ -9,7 +9,63 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-06-21 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sequel
|
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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
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'
|
13
69
|
description: For more detail please visit https://github.com/abbish/abbish_sequel_plugins
|
14
70
|
email:
|
15
71
|
- me@abbish.com
|
@@ -17,10 +73,21 @@ executables: []
|
|
17
73
|
extensions: []
|
18
74
|
extra_rdoc_files: []
|
19
75
|
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- abbish_sequel_plugins.gemspec
|
20
83
|
- lib/abbish_sequel_plugins.rb
|
21
84
|
- lib/model/record_protection.rb
|
22
85
|
- lib/model/record_timestamp.rb
|
23
86
|
- lib/model/record_version.rb
|
87
|
+
- spec/lib/model.rb
|
88
|
+
- spec/record_protection_spec.rb
|
89
|
+
- spec/record_timestamp_spec.rb
|
90
|
+
- spec/record_version_spec.rb
|
24
91
|
homepage: https://github.com/abbish/abbish-sequel-plugins
|
25
92
|
licenses:
|
26
93
|
- MIT
|