uidable 1.1.0 → 2.0.0
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/README.md +8 -4
- data/lib/uidable.rb +14 -10
- data/lib/uidable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 932433d8f3888343b55428409e091316f90f5e41
|
|
4
|
+
data.tar.gz: 2004454ac043c3bc3e8dcbccecd141e1f1c4dfb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e6e856d7c9c914ac5b02755ad779011374286a198061d5c62524346adf1effc28e73ac3600b00d91f390837dc6ce666f441aec8512827bb206883797447e70a
|
|
7
|
+
data.tar.gz: 8663d0c4cb2790a919d73e20d8b72d9de7d664761e56ed64be11fbdcd6ec61bd4c0af235de6f47090de844714f29b221a3920f14a944f377a6a7b2de1b7d70a4
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[travis]: https://travis-ci.org/sibevin/uidable
|
|
9
9
|
[coveralls]: https://coveralls.io/github/sibevin/uidable?branch=cover-check
|
|
10
10
|
|
|
11
|
-
Create the uid(
|
|
11
|
+
Create the uid(unique identifier) attribute in your model or class.
|
|
12
12
|
|
|
13
13
|
## Installation
|
|
14
14
|
|
|
@@ -90,13 +90,17 @@ The uid is read only by default. You can disabled it with `read_only: false`.
|
|
|
90
90
|
|
|
91
91
|
## Options for ActiveRecord
|
|
92
92
|
|
|
93
|
-
###
|
|
93
|
+
### Presence
|
|
94
94
|
|
|
95
|
-
The
|
|
95
|
+
The presence validation is enabled by default. You can disable them with `presence: false`.
|
|
96
|
+
|
|
97
|
+
### Uniqueness
|
|
98
|
+
|
|
99
|
+
There are three options for the uniqueness validation - `:create`, `:always`, `:none`. `:create` is the default option, it means only check the uniqueness when creating a record. `:always` means doing uniqueness validation each time when the model is saved. `:none` means the uniqueness validation is disabled. Note that you should change your migration to support uniqueness as well if needed.
|
|
96
100
|
|
|
97
101
|
### Set to_param
|
|
98
102
|
|
|
99
|
-
If the option `set_to_param: true` is given, the `to_param` is
|
|
103
|
+
If the option `set_to_param: true` is given, the `to_param` is overridden with uid and it means you can use uid in your routes path.
|
|
100
104
|
|
|
101
105
|
### Scope
|
|
102
106
|
|
data/lib/uidable.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'uidable/version'
|
|
2
2
|
|
|
3
3
|
module Uidable
|
|
4
4
|
DEFAULT_UID_SIZE = 32
|
|
@@ -27,29 +27,34 @@ module Uidable
|
|
|
27
27
|
|
|
28
28
|
module ClassMethods
|
|
29
29
|
def uidable(
|
|
30
|
-
uid_name:
|
|
30
|
+
uid_name: 'uid',
|
|
31
31
|
uid_size: DEFAULT_UID_SIZE,
|
|
32
32
|
read_only: true,
|
|
33
33
|
presence: true,
|
|
34
|
-
uniqueness:
|
|
34
|
+
uniqueness: :create,
|
|
35
35
|
set_to_param: false,
|
|
36
36
|
scope: false)
|
|
37
37
|
unless uidable_cols.include?(uid_name.to_sym)
|
|
38
|
+
uniqueness_check = case (uniqueness.to_sym)
|
|
39
|
+
when :create then "base.validates :'#{uid_name}', uniqueness: true, on: :create"
|
|
40
|
+
when :always then "base.validates :'#{uid_name}', uniqueness: true"
|
|
41
|
+
else ''
|
|
42
|
+
end
|
|
38
43
|
uidable_cols << uid_name.to_sym
|
|
39
44
|
mod = Module.new
|
|
40
45
|
mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
|
41
46
|
def self.included(base)
|
|
42
47
|
if defined?(::ActiveRecord::Base) && base < ::ActiveRecord::Base
|
|
43
48
|
base.before_validation :uidable_assign_#{uid_name}, on: :create
|
|
44
|
-
#{
|
|
45
|
-
#{
|
|
46
|
-
#{
|
|
49
|
+
#{scope ? "base.scope :'with_#{uid_name}', -> (uid) { base.where(:'#{uid_name}' => uid) }" : ''}
|
|
50
|
+
#{set_to_param ? "base.include SetToParam#{uid_name}" : ''}
|
|
51
|
+
#{read_only ? "base.attr_readonly :'#{uid_name}'" : ''}
|
|
47
52
|
else
|
|
48
|
-
#{
|
|
53
|
+
#{read_only ? "attr_reader :'#{uid_name}'" : "attr_accessor :'#{uid_name}'"}
|
|
49
54
|
end
|
|
50
55
|
if base.respond_to?(:validates)
|
|
51
|
-
#{
|
|
52
|
-
#{
|
|
56
|
+
#{presence ? "base.validates :'#{uid_name}', presence: true" : ''}
|
|
57
|
+
#{uniqueness_check}
|
|
53
58
|
end
|
|
54
59
|
end
|
|
55
60
|
|
|
@@ -77,5 +82,4 @@ module Uidable
|
|
|
77
82
|
@uidable_cols ||= []
|
|
78
83
|
end
|
|
79
84
|
end
|
|
80
|
-
|
|
81
85
|
end
|
data/lib/uidable/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uidable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sibevin Wang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-06-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
78
78
|
version: '0'
|
|
79
79
|
requirements: []
|
|
80
80
|
rubyforge_project:
|
|
81
|
-
rubygems_version: 2.4.
|
|
81
|
+
rubygems_version: 2.4.5.1
|
|
82
82
|
signing_key:
|
|
83
83
|
specification_version: 4
|
|
84
84
|
summary: Create the uid attribute in your model or class.
|