uniq-registor 0.0.3.1
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.
- data/lib/registor/registor_callbacks.rb +39 -0
- data/lib/registor/registor_conf.rb +13 -0
- data/lib/registor.rb +7 -0
- metadata +68 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module RegistorCallbacks
|
|
2
|
+
def self.included(base)
|
|
3
|
+
base.extend ClassMethods
|
|
4
|
+
base.class_eval do
|
|
5
|
+
before_create :set_primary_key_value
|
|
6
|
+
end
|
|
7
|
+
base.send :include, InstanceMethods
|
|
8
|
+
end # self.included
|
|
9
|
+
|
|
10
|
+
module ClassMethods
|
|
11
|
+
def regist_uniq_id
|
|
12
|
+
RegistorConf.redis.incr("#{RegistorConf.name_space}:#{self.name}:uniq_id")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def current_uniq_id_value
|
|
16
|
+
RegistorConf.redis.get("#{RegistorConf.name_space}:#{self.name}:uniq_id")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def regist_uniq_name(field_name, name)
|
|
20
|
+
RegistorConf.redis.sadd "#{RegistorConf.name_space}:#{self.name}:#{field_name}", name
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def uniq_name_count(field_name)
|
|
24
|
+
RegistorConf.redis.scard "#{RegistorConf.name_space}:#{self.name}:#{field_name}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def rem_uniq_name(field_name, name)
|
|
28
|
+
RegistorConf.redis.srem "#{RegistorConf.name_space}:#{self.name}:#{field_name}", name
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end # ClassMethods
|
|
32
|
+
|
|
33
|
+
module InstanceMethods
|
|
34
|
+
private
|
|
35
|
+
def set_primary_key_value
|
|
36
|
+
self.send "#{self.class.primary_key}=", self.class.regist_uniq_id
|
|
37
|
+
end
|
|
38
|
+
end # InstanceMethods
|
|
39
|
+
end
|
data/lib/registor.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: uniq-registor
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 65
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 3
|
|
10
|
+
- 1
|
|
11
|
+
version: 0.0.3.1
|
|
12
|
+
platform: ruby
|
|
13
|
+
authors:
|
|
14
|
+
- Savin Max
|
|
15
|
+
autorequire:
|
|
16
|
+
bindir: bin
|
|
17
|
+
cert_chain: []
|
|
18
|
+
|
|
19
|
+
date: 2012-05-25 00:00:00 Z
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: ""
|
|
23
|
+
email: mafei.198@gmail.com
|
|
24
|
+
executables: []
|
|
25
|
+
|
|
26
|
+
extensions: []
|
|
27
|
+
|
|
28
|
+
extra_rdoc_files: []
|
|
29
|
+
|
|
30
|
+
files:
|
|
31
|
+
- lib/registor.rb
|
|
32
|
+
- lib/registor/registor_callbacks.rb
|
|
33
|
+
- lib/registor/registor_conf.rb
|
|
34
|
+
homepage: https://github.com/mafei198/uniq_registor
|
|
35
|
+
licenses: []
|
|
36
|
+
|
|
37
|
+
post_install_message:
|
|
38
|
+
rdoc_options: []
|
|
39
|
+
|
|
40
|
+
require_paths:
|
|
41
|
+
- lib
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
none: false
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
hash: 3
|
|
48
|
+
segments:
|
|
49
|
+
- 0
|
|
50
|
+
version: "0"
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
hash: 3
|
|
57
|
+
segments:
|
|
58
|
+
- 0
|
|
59
|
+
version: "0"
|
|
60
|
+
requirements: []
|
|
61
|
+
|
|
62
|
+
rubyforge_project:
|
|
63
|
+
rubygems_version: 1.8.19
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 3
|
|
66
|
+
summary: Redis based uniq-registor for regist unique name or id for rails model
|
|
67
|
+
test_files: []
|
|
68
|
+
|