abbish_sequel_plugins 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +32 -12
- data/ROADMAP.md +0 -0
- data/lib/abbish_sequel_plugins.rb +2 -4
- data/lib/model/super_record.rb +14 -0
- data/lib/model/super_record/protection.rb +59 -0
- data/lib/model/super_record/timestamp.rb +55 -0
- data/lib/model/super_record/version.rb +51 -0
- data/spec/lib/model.rb +3 -3
- data/spec/record_protection_spec.rb +1 -1
- metadata +8 -5
- data/lib/model/record_protection.rb +0 -58
- data/lib/model/record_timestamp.rb +0 -52
- data/lib/model/record_version.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee09a952841117aad025b955e74db5ce3f0c407
|
4
|
+
data.tar.gz: 8295bb4936daca837c4cafcb7d941b7999665176
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 037cadecd214d0a08126dafa9deb1dac237b219791763ba396d47577d16b6d4e3fd1c65b61dcb93a80432997a69f81119e619a1b91aa1939b806781f0dbb5fb3
|
7
|
+
data.tar.gz: 968a490e455c62705595ebd370955fa0c5481184d7e1e4fe49fe3f137fb5065b2ccb856125d18ff9deb3dd367580936a3ccef79a21306bd51e0ce27d7f1103b5
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -18,51 +18,71 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install abbish_sequel_plugins
|
20
20
|
|
21
|
-
##
|
22
|
-
|
23
|
-
|
21
|
+
## Plugin super_record
|
22
|
+
###protection
|
23
|
+
Protecting record cannot destroy and raise error when destroy it
|
24
24
|
```ruby
|
25
25
|
class Model < Sequel::Model(:test_table)
|
26
|
-
plugin Abbish::Sequel::Plugins::Model::
|
26
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Protection { options }
|
27
27
|
end
|
28
28
|
```
|
29
29
|
Default options
|
30
30
|
```ruby
|
31
31
|
{
|
32
32
|
:enabled => true,
|
33
|
-
:
|
33
|
+
:feature_column_protected => :record_protected,
|
34
34
|
:raise_protected_message => 'Cannot destroy protected record'
|
35
35
|
}
|
36
36
|
```
|
37
|
+
Usage
|
38
|
+
```ruby
|
39
|
+
model = Model.create(:table_field => 'test')
|
40
|
+
```
|
41
|
+
use ```set_record_protected!``` to set record being protected
|
42
|
+
```ruby
|
43
|
+
model.set_record_protected!
|
44
|
+
```
|
45
|
+
or use ```set_record_protected``` and ```save``` to set record being protected
|
46
|
+
```ruby
|
47
|
+
model.set_record_protected
|
48
|
+
model.save
|
49
|
+
```
|
50
|
+
```ruby
|
51
|
+
# Destroy a protected record will raise a ProtectedError
|
52
|
+
model.destroy
|
53
|
+
```
|
37
54
|
======
|
38
|
-
###
|
55
|
+
###timestamp
|
56
|
+
Automatically add current date time to record when record was created and updated
|
39
57
|
```ruby
|
40
58
|
class Model < Sequel::Model(:test_table)
|
41
|
-
plugin Abbish::Sequel::Plugins::Model::
|
59
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Timestamp { options }
|
42
60
|
end
|
43
61
|
```
|
44
62
|
Default options
|
45
63
|
```ruby
|
46
64
|
{
|
47
65
|
:enabled => true,
|
48
|
-
:
|
49
|
-
:
|
66
|
+
:feature_column_created_time => :record_created_time,
|
67
|
+
:feature_column_updated_time => :record_updated_time
|
50
68
|
}
|
51
69
|
```
|
52
70
|
======
|
53
|
-
###
|
71
|
+
###version
|
72
|
+
Automatically generate hash string be record version when record was created and updated
|
54
73
|
```ruby
|
55
74
|
class Model < Sequel::Model(:test_table)
|
56
|
-
plugin Abbish::Sequel::Plugins::Model::
|
75
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Version
|
57
76
|
end
|
58
77
|
```
|
59
78
|
Default options
|
60
79
|
```ruby
|
61
80
|
{
|
62
81
|
:enabled => true,
|
63
|
-
:
|
82
|
+
:feature_column_version => :record_version
|
64
83
|
}
|
65
84
|
```
|
85
|
+
======
|
66
86
|
## Contributing
|
67
87
|
|
68
88
|
1. Fork it ( https://github.com/abbish/abbish_sequel_plugins/fork )
|
data/ROADMAP.md
ADDED
File without changes
|
@@ -1,12 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require File.dirname(__FILE__) + '/model/
|
3
|
-
require File.dirname(__FILE__) + '/model/record_protection'
|
4
|
-
require File.dirname(__FILE__) + '/model/record_timestamp'
|
2
|
+
require File.dirname(__FILE__) + '/model/super_record'
|
5
3
|
|
6
4
|
module Abbish
|
7
5
|
module Sequel
|
8
6
|
module Plugins
|
9
|
-
Version = '0.0.
|
7
|
+
Version = '0.0.5'
|
10
8
|
end
|
11
9
|
end
|
12
10
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/super_record/version'
|
2
|
+
require File.dirname(__FILE__) + '/super_record/protection'
|
3
|
+
require File.dirname(__FILE__) + '/super_record/timestamp'
|
4
|
+
|
5
|
+
module Abbish
|
6
|
+
module Sequel
|
7
|
+
module Plugins
|
8
|
+
module Model
|
9
|
+
module SuperRecord
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Abbish
|
2
|
+
module Sequel
|
3
|
+
module Plugins
|
4
|
+
module Model
|
5
|
+
module SuperRecord
|
6
|
+
module Protection
|
7
|
+
ProtectedError = Class.new(::StandardError)
|
8
|
+
def self.configure(model, options = {})
|
9
|
+
options = {
|
10
|
+
:enabled => true,
|
11
|
+
:feature_column_protected => :record_protected,
|
12
|
+
:raise_protected_message => 'Cannot destroy protected record',
|
13
|
+
}.merge(options)
|
14
|
+
|
15
|
+
model.instance_eval do
|
16
|
+
self.record_protection_options = options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def record_protection_options=(options)
|
22
|
+
@record_protection_options = options
|
23
|
+
end
|
24
|
+
|
25
|
+
def record_protection_options
|
26
|
+
@record_protection_options
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module InstanceMethods
|
31
|
+
|
32
|
+
def record_protected?
|
33
|
+
self.class.record_protection_options[:enabled] ? send("#{self.class.record_protection_options[:feature_column_protected]}") == 1 : false
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_record_protected
|
37
|
+
send("#{self.class.record_protection_options[:feature_column_protected]}=", 1) if self.class.record_protection_options[:enabled]
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_record_protected!
|
41
|
+
if self.class.record_protection_options[:enabled]
|
42
|
+
set_record_protected
|
43
|
+
self.save
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def before_destroy
|
48
|
+
super
|
49
|
+
raise ProtectedError, self.class.record_protection_options[:raise_protected_message] if record_protected?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Abbish
|
2
|
+
module Sequel
|
3
|
+
module Plugins
|
4
|
+
module Model
|
5
|
+
module SuperRecord
|
6
|
+
module Timestamp
|
7
|
+
def self.configure(model, options = {})
|
8
|
+
options = {
|
9
|
+
:enabled => true,
|
10
|
+
:feature_column_created_time => :record_created_time,
|
11
|
+
:feature_column_updated_time => :record_updated_time,
|
12
|
+
}.merge(options)
|
13
|
+
|
14
|
+
model.instance_eval do
|
15
|
+
self.record_timestamp_options = options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module ClassMethods
|
20
|
+
def record_timestamp_options=(options)
|
21
|
+
@record_timestamp_options = options
|
22
|
+
end
|
23
|
+
|
24
|
+
def record_timestamp_options
|
25
|
+
@record_timestamp_options
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
module InstanceMethods
|
30
|
+
|
31
|
+
def before_create
|
32
|
+
send("#{self.class.record_timestamp_options[:feature_column_created_time]}=", _get_time) if self.class.record_timestamp_options[:enabled]
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
def before_update
|
37
|
+
send("#{self.class.record_timestamp_options[:feature_column_updated_time]}=", _get_time) if self.class.record_timestamp_options[:enabled] if self.modified?
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def _get_time
|
44
|
+
return Time.now
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Abbish
|
2
|
+
module Sequel
|
3
|
+
module Plugins
|
4
|
+
module Model
|
5
|
+
module SuperRecord
|
6
|
+
module Version
|
7
|
+
def self.configure(model, options = {})
|
8
|
+
options = {
|
9
|
+
:enabled => true,
|
10
|
+
:feature_column_version => :record_version,
|
11
|
+
}.merge(options)
|
12
|
+
|
13
|
+
model.instance_eval do
|
14
|
+
self.record_version_options = options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ClassMethods
|
19
|
+
def record_version_options=(options)
|
20
|
+
@record_version_options = options
|
21
|
+
end
|
22
|
+
|
23
|
+
def record_version_options
|
24
|
+
@record_version_options
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
|
30
|
+
def before_create
|
31
|
+
send("#{self.class.record_version_options[:feature_column_version]}=", _get_version) if self.class.record_version_options[:enabled]
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def before_update
|
36
|
+
send("#{self.class.record_version_options[:feature_column_version]}=", _get_version) if self.class.record_version_options[:enabled] if self.modified?
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def _get_version
|
43
|
+
return Digest::MD5.hexdigest Time.now.to_f.to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/lib/model.rb
CHANGED
@@ -14,7 +14,7 @@ Sequel::Model.db.create_table :test_table do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Model < Sequel::Model(:test_table)
|
17
|
-
plugin Abbish::Sequel::Plugins::Model::
|
18
|
-
plugin Abbish::Sequel::Plugins::Model::
|
19
|
-
plugin Abbish::Sequel::Plugins::Model::
|
17
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Protection
|
18
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Timestamp
|
19
|
+
plugin Abbish::Sequel::Plugins::Model::SuperRecord::Version
|
20
20
|
end
|
@@ -31,7 +31,7 @@ describe 'RecordProtectionSpec' do
|
|
31
31
|
@model.set_record_protected!
|
32
32
|
|
33
33
|
model = Model[@model.id]
|
34
|
-
proc { model.destroy }.must_raise Abbish::Sequel::Plugins::Model::
|
34
|
+
proc { model.destroy }.must_raise Abbish::Sequel::Plugins::Model::SuperRecord::Protection::ProtectedError
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- abbish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -74,16 +74,19 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- CHANGELOG.md
|
77
78
|
- Gemfile
|
78
79
|
- Gemfile.lock
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
82
|
+
- ROADMAP.md
|
81
83
|
- Rakefile
|
82
84
|
- abbish_sequel_plugins.gemspec
|
83
85
|
- lib/abbish_sequel_plugins.rb
|
84
|
-
- lib/model/
|
85
|
-
- lib/model/
|
86
|
-
- lib/model/
|
86
|
+
- lib/model/super_record.rb
|
87
|
+
- lib/model/super_record/protection.rb
|
88
|
+
- lib/model/super_record/timestamp.rb
|
89
|
+
- lib/model/super_record/version.rb
|
87
90
|
- spec/lib/model.rb
|
88
91
|
- spec/record_protection_spec.rb
|
89
92
|
- spec/record_timestamp_spec.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Abbish
|
2
|
-
module Sequel
|
3
|
-
module Plugins
|
4
|
-
module Model
|
5
|
-
|
6
|
-
RecordProtectedError = Class.new(::StandardError)
|
7
|
-
|
8
|
-
module RecordProtection
|
9
|
-
def self.configure(model, options = {})
|
10
|
-
options = {
|
11
|
-
:enabled => true,
|
12
|
-
:column_protected => :record_protected,
|
13
|
-
:raise_protected_message => 'Cannot destroy protected record',
|
14
|
-
}.merge(options)
|
15
|
-
|
16
|
-
model.instance_eval do
|
17
|
-
self.record_protection_options = options
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module ClassMethods
|
22
|
-
def record_protection_options=(options)
|
23
|
-
@record_protection_options = options
|
24
|
-
end
|
25
|
-
|
26
|
-
def record_protection_options
|
27
|
-
@record_protection_options
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
module InstanceMethods
|
32
|
-
|
33
|
-
def record_protected?
|
34
|
-
self.class.record_protection_options[:enabled] ? send("#{self.class.record_protection_options[:column_protected]}") == 1 : false
|
35
|
-
end
|
36
|
-
|
37
|
-
def set_record_protected
|
38
|
-
send("#{self.class.record_protection_options[:column_protected]}=", 1) if self.class.record_protection_options[:enabled]
|
39
|
-
end
|
40
|
-
|
41
|
-
def set_record_protected!
|
42
|
-
if self.class.record_protection_options[:enabled]
|
43
|
-
set_record_protected
|
44
|
-
self.save
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def before_destroy
|
49
|
-
super
|
50
|
-
raise RecordProtectedError, self.class.record_protection_options[:raise_protected_message] if record_protected?
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Abbish
|
2
|
-
module Sequel
|
3
|
-
module Plugins
|
4
|
-
module Model
|
5
|
-
module RecordTimestamp
|
6
|
-
def self.configure(model, options = {})
|
7
|
-
options = {
|
8
|
-
:enabled => true,
|
9
|
-
:column_created_time => :record_created_time,
|
10
|
-
:column_updated_time => :record_updated_time,
|
11
|
-
}.merge(options)
|
12
|
-
|
13
|
-
model.instance_eval do
|
14
|
-
self.record_timestamp_options = options
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
def record_timestamp_options=(options)
|
20
|
-
@record_timestamp_options = options
|
21
|
-
end
|
22
|
-
|
23
|
-
def record_timestamp_options
|
24
|
-
@record_timestamp_options
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module InstanceMethods
|
29
|
-
|
30
|
-
def before_create
|
31
|
-
self.record_created_time = _get_time if self.class.record_timestamp_options[:enabled]
|
32
|
-
super
|
33
|
-
end
|
34
|
-
|
35
|
-
def before_update
|
36
|
-
self.record_updated_time = _get_time if self.class.record_timestamp_options[:enabled] if self.modified?
|
37
|
-
super
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def _get_time
|
43
|
-
return Time.now
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
|
data/lib/model/record_version.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
module Abbish
|
2
|
-
module Sequel
|
3
|
-
module Plugins
|
4
|
-
module Model
|
5
|
-
module RecordVersion
|
6
|
-
def self.configure(model, options = {})
|
7
|
-
options = {
|
8
|
-
:enabled => true,
|
9
|
-
:column_version => :record_version,
|
10
|
-
}.merge(options)
|
11
|
-
|
12
|
-
model.instance_eval do
|
13
|
-
self.record_version_options = options
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
def record_version_options=(options)
|
19
|
-
@record_version_options = options
|
20
|
-
end
|
21
|
-
|
22
|
-
def record_version_options
|
23
|
-
@record_version_options
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
module InstanceMethods
|
28
|
-
|
29
|
-
def before_create
|
30
|
-
self.record_version = _get_version if self.class.record_version_options[:enabled]
|
31
|
-
super
|
32
|
-
end
|
33
|
-
|
34
|
-
def before_update
|
35
|
-
self.record_version = _get_version if self.class.record_version_options[:enabled] if self.modified?
|
36
|
-
super
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def _get_version
|
42
|
-
return Digest::MD5.hexdigest Time.now.to_f.to_s
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|