has_uuid 0.0.7 → 0.0.8
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/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/CHANGELOG.md +1 -0
- data/README.markdown +23 -37
- data/has_uuid.gemspec +1 -1
- data/lib/has_uuid.rb +15 -24
- data/lib/has_uuid/version.rb +1 -1
- data/test/has_uuid_test.rb +8 -0
- metadata +52 -65
data/.gitignore
CHANGED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.2-p180@has_uuid
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* (troessner) Refactor the whole gem and use `class_attribute`.
|
data/README.markdown
CHANGED
@@ -5,15 +5,7 @@ has_uuid
|
|
5
5
|
|
6
6
|
It depends on the [uuidtools](http://uuidtools.rubyforge.org/) gem.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
What I changed:
|
11
|
-
|
12
|
-
a) Made it rails 3.1 compatible.
|
13
|
-
|
14
|
-
b) Bundler'ized it - you can now use and manage it as a gem, not as a rails plugin.
|
15
|
-
|
16
|
-
c) Added generate_uuid as a class method
|
8
|
+
Initial credits go to [has_uuid](http://github.com/norbert/has_uuid).
|
17
9
|
|
18
10
|
Installation
|
19
11
|
------------
|
@@ -29,39 +21,33 @@ to your Gemfile and run
|
|
29
21
|
Usage
|
30
22
|
-----
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
class Comment < ActiveRecord::Base
|
38
|
-
# skip assignment on create
|
39
|
-
has_uuid :auto => false
|
40
|
-
end
|
24
|
+
class Post < ActiveRecord::Base
|
25
|
+
# automatically assign a UUID to the "uuid" column on create
|
26
|
+
has_uuid
|
27
|
+
end
|
41
28
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
class Comment < ActiveRecord::Base
|
30
|
+
# skip assignment on create
|
31
|
+
has_uuid :auto => false
|
32
|
+
end
|
46
33
|
|
47
|
-
|
48
|
-
|
34
|
+
class User < ActiveRecord::Base
|
35
|
+
# store the UUID in the "token" column
|
36
|
+
has_uuid :column => :token, :generator => :timestamp
|
37
|
+
end
|
49
38
|
|
50
|
-
|
51
|
-
|
39
|
+
# assign a UUID if a valid one is not already present
|
40
|
+
@post.assign_uuid
|
52
41
|
|
53
|
-
|
54
|
-
|
42
|
+
# assign a UUID, replacing whatever is already there
|
43
|
+
@post.assign_uuid(:force => true)
|
55
44
|
|
56
|
-
|
57
|
-
|
45
|
+
# assign a UUID and save, replacing whatever is there
|
46
|
+
@post.assign_uuid!
|
58
47
|
|
59
|
-
|
60
|
-
|
48
|
+
# check if the current UUID is valid
|
49
|
+
@post.uuid_valid?
|
61
50
|
|
62
|
-
|
63
|
-
|
51
|
+
# Generate a UUID to use it later
|
52
|
+
Post.generate_uuid
|
64
53
|
|
65
|
-
* Norbert Crombach
|
66
|
-
* Todd Eichel
|
67
|
-
* Joerg Batterman
|
data/has_uuid.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
s.require_paths = ["lib"]
|
18
|
-
s.add_dependency 'activerecord', '
|
18
|
+
s.add_dependency 'activerecord', '~> 3.1.0'
|
19
19
|
s.add_dependency 'uuidtools'
|
20
20
|
s.add_development_dependency 'rake'
|
21
21
|
s.add_development_dependency 'sqlite3'
|
data/lib/has_uuid.rb
CHANGED
@@ -1,34 +1,26 @@
|
|
1
1
|
require 'uuidtools'
|
2
2
|
|
3
|
-
module ActiveRecord
|
4
|
-
module Acts
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
#
|
9
|
-
# class Post < ActiveRecord::Base
|
10
|
-
# has_uuid
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# That is all.
|
3
|
+
module ActiveRecord
|
4
|
+
module Acts
|
5
|
+
# has_uuid adds a UUID to your models. See the README for details.
|
14
6
|
module HasUuid
|
15
|
-
GENERATORS = [:random, :timestamp]
|
7
|
+
GENERATORS = [:random, :timestamp]
|
8
|
+
DEFAULT_OPTIONS = {:auto => true, :generator => :random, :column => :uuid}
|
16
9
|
|
17
|
-
#
|
18
|
-
#
|
19
|
-
# *
|
20
|
-
# *
|
21
|
-
# *
|
10
|
+
# Class Macro which actually lets models use has_uuid
|
11
|
+
# @param options:
|
12
|
+
# * column: The column in which to store the UUID (default: uuid).
|
13
|
+
# * auto: Assign a UUID on create (default: true).
|
14
|
+
# * generator The UUID generator. Possible values are `random` default) and `timestamp`.
|
22
15
|
def has_uuid(options = {})
|
23
|
-
options.reverse_merge!
|
24
|
-
raise ArgumentError, "
|
16
|
+
options.reverse_merge! DEFAULT_OPTIONS
|
17
|
+
raise ArgumentError, "Invalid UUID generator #{options[:generator]}" unless GENERATORS.include?(options[:generator])
|
25
18
|
|
26
19
|
class_eval do
|
27
|
-
|
20
|
+
include InstanceMethods
|
28
21
|
|
29
22
|
if options[:auto]
|
30
|
-
|
31
|
-
before_validation(:on => :create) { assign_uuid }
|
23
|
+
before_save(:on => :create) { assign_uuid }
|
32
24
|
end
|
33
25
|
|
34
26
|
class_attribute :uuid_column
|
@@ -43,8 +35,7 @@ module ActiveRecord #:nodoc:
|
|
43
35
|
UUIDTools::UUID.send("#{uuid_generator}_create").to_s
|
44
36
|
end
|
45
37
|
|
46
|
-
|
47
|
-
module InstanceMethods #:nodoc:
|
38
|
+
module InstanceMethods
|
48
39
|
def assign_uuid(options = {})
|
49
40
|
return if uuid_valid? unless options[:force]
|
50
41
|
|
data/lib/has_uuid/version.rb
CHANGED
data/test/has_uuid_test.rb
CHANGED
@@ -85,4 +85,12 @@ class HasUuidTest < Test::Unit::TestCase
|
|
85
85
|
@thingy.reload
|
86
86
|
assert_nil @thingy.uuid
|
87
87
|
end
|
88
|
+
|
89
|
+
def should_assign_an_uuid_if_we_do_not_validate_the_overall_record
|
90
|
+
@widget = Widget.new
|
91
|
+
assert_nil @widget.uuid
|
92
|
+
@widget.save :validate => false
|
93
|
+
@widget.reload
|
94
|
+
assert @widget.uuid_valid?
|
95
|
+
end
|
88
96
|
end
|
metadata
CHANGED
@@ -1,73 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_uuid
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.7
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Timo Rößner
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-27 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: activerecord
|
18
|
-
requirement: &
|
16
|
+
requirement: &77501590 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *77501590
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: uuidtools
|
29
|
-
requirement: &
|
27
|
+
requirement: &77501200 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
35
33
|
type: :runtime
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *77501200
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
name: rake
|
40
|
-
requirement: &
|
38
|
+
requirement: &77500880 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
46
44
|
type: :development
|
47
45
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
46
|
+
version_requirements: *77500880
|
47
|
+
- !ruby/object:Gem::Dependency
|
50
48
|
name: sqlite3
|
51
|
-
requirement: &
|
49
|
+
requirement: &77500450 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version:
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
57
55
|
type: :development
|
58
56
|
prerelease: false
|
59
|
-
version_requirements: *
|
57
|
+
version_requirements: *77500450
|
60
58
|
description: The has_uuid gem adds a UUID to your AR models. See the README for details.
|
61
|
-
email:
|
59
|
+
email:
|
62
60
|
- timo.roessner@googlemail.com
|
63
61
|
executables: []
|
64
|
-
|
65
62
|
extensions: []
|
66
|
-
|
67
63
|
extra_rdoc_files: []
|
68
|
-
|
69
|
-
files:
|
64
|
+
files:
|
70
65
|
- .gitignore
|
66
|
+
- .has_uuid.gemspec.swp
|
67
|
+
- .rvmrc
|
68
|
+
- CHANGELOG.md
|
71
69
|
- Gemfile
|
72
70
|
- LICENSE
|
73
71
|
- README.markdown
|
@@ -78,39 +76,28 @@ files:
|
|
78
76
|
- rails/init.rb
|
79
77
|
- test/has_uuid_test.rb
|
80
78
|
- test/test_helper.rb
|
81
|
-
has_rdoc: true
|
82
79
|
homepage: https://github.com/troessner/has_uuid
|
83
80
|
licenses: []
|
84
|
-
|
85
81
|
post_install_message:
|
86
82
|
rdoc_options: []
|
87
|
-
|
88
|
-
require_paths:
|
83
|
+
require_paths:
|
89
84
|
- lib
|
90
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
86
|
none: false
|
92
|
-
requirements:
|
93
|
-
- -
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
|
96
|
-
|
97
|
-
- 0
|
98
|
-
version: "0"
|
99
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
92
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
|
105
|
-
segments:
|
106
|
-
- 0
|
107
|
-
version: "0"
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
108
97
|
requirements: []
|
109
|
-
|
110
98
|
rubyforge_project:
|
111
|
-
rubygems_version: 1.
|
99
|
+
rubygems_version: 1.8.12
|
112
100
|
signing_key:
|
113
101
|
specification_version: 3
|
114
102
|
summary: The has_uuid gem adds a UUID to your AR models.
|
115
103
|
test_files: []
|
116
|
-
|