uuid_it 0.0.1 → 0.0.2
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/README.md +13 -1
- data/lib/uuid_it.rb +1 -0
- data/test/test_helper.rb +20 -1
- data/test/uuid_it_test.rb +32 -3
- metadata +5 -5
data/README.md
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# UuidIt
|
2
2
|
|
3
|
-
You need to assign UUIDs to your Model?
|
3
|
+
You need to assign UUIDs to your Model? UuidIt makes it as simple as adding one line of code to the according models.
|
4
4
|
|
5
5
|
For actually generating the uuids this plugin uses spectra's ruby-uuid (http://github.com/spectra/ruby-uuid) whih is
|
6
6
|
based on ruby-uuid (http://raa.ruby-lang.org/project/ruby-uuid/).
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
10
|
+
### As a plugin
|
11
|
+
|
10
12
|
script/plugin install git://github.com/aduffeck/uuid_it.git
|
11
13
|
script/generate uuid_it
|
12
14
|
rake db:migrate
|
13
15
|
|
16
|
+
### As a gem
|
17
|
+
Add the following line to your config/environment.rb file:
|
18
|
+
|
19
|
+
config.gem "uuid_it"
|
20
|
+
|
21
|
+
script/generate uuid_it
|
22
|
+
rake db:migrate
|
14
23
|
|
15
24
|
## Usage
|
16
25
|
|
@@ -20,6 +29,9 @@ based on ruby-uuid (http://raa.ruby-lang.org/project/ruby-uuid/).
|
|
20
29
|
|
21
30
|
@car.uuid # "9e5edacc-7163-11df-92bb-2d0a2c4dcb1c"
|
22
31
|
|
32
|
+
New UUIDs will be assigned when new objects are created. Already existing objects will get a UUID when it is read for the
|
33
|
+
first time.
|
34
|
+
|
23
35
|
## Credits
|
24
36
|
|
25
37
|
Copyright (c) 2010 André Duffeck, released under the MIT license
|
data/lib/uuid_it.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_support'
|
3
|
-
require 'active_support/test_case'
|
3
|
+
require 'active_support/test_case'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'active_record'
|
6
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/../lib/uuid_it'
|
9
|
+
|
10
|
+
silence_stream(STDOUT) do
|
11
|
+
ActiveRecord::Schema.define do
|
12
|
+
create_table :uuids do |t|
|
13
|
+
t.string :uuid
|
14
|
+
t.integer :uuidable_id
|
15
|
+
t.string :uuidable_type, :limit => 40
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :cars
|
19
|
+
|
20
|
+
create_table :bikes
|
21
|
+
end
|
22
|
+
end
|
data/test/uuid_it_test.rb
CHANGED
@@ -1,8 +1,37 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class Car < ActiveRecord::Base
|
4
|
+
uuid_it
|
5
|
+
end
|
6
|
+
|
7
|
+
class Bike < ActiveRecord::Base
|
8
|
+
end
|
9
|
+
|
3
10
|
class UuidItTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
|
6
|
-
assert
|
11
|
+
test "should assing Uuids to new objects" do
|
12
|
+
c = Car.create
|
13
|
+
assert c.uuid_object
|
14
|
+
assert c.uuid.present?
|
15
|
+
|
16
|
+
c2 = Car.create
|
17
|
+
assert_not_equal c.uuid, c2.uuid
|
18
|
+
end
|
19
|
+
|
20
|
+
test "should assing Uuid to already existing objects on first access" do
|
21
|
+
b1 = nil
|
22
|
+
assert_difference "Uuid.count", 0 do
|
23
|
+
b1 = Bike.create
|
24
|
+
end
|
25
|
+
Bike.class_eval do
|
26
|
+
uuid_it
|
27
|
+
end
|
28
|
+
assert_nil b1.uuid_object
|
29
|
+
b1.uuid
|
30
|
+
assert b1.uuid_object
|
31
|
+
assert b1.uuid.present?
|
32
|
+
|
33
|
+
b2 = Bike.create
|
34
|
+
assert b2.uuid_object
|
35
|
+
assert b2.uuid.present?
|
7
36
|
end
|
8
37
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Andr\xC3\xA9 Duffeck"
|
@@ -14,11 +14,11 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-06-
|
17
|
+
date: 2010-06-07 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description: " You need to assign UUIDs to your model? UuidIt makes it as simple adding one line of code to the according models. \n"
|
21
|
+
description: " You need to assign UUIDs to your model? UuidIt makes it as simple as adding one line of code to the according models. \n"
|
22
22
|
email:
|
23
23
|
- aduffeck@suse.de
|
24
24
|
executables: []
|
@@ -39,7 +39,7 @@ files:
|
|
39
39
|
- test/test_helper.rb
|
40
40
|
- test/uuid_it_test.rb
|
41
41
|
has_rdoc: true
|
42
|
-
homepage: http://
|
42
|
+
homepage: http://github.com/aduffeck/uuid_it
|
43
43
|
licenses: []
|
44
44
|
|
45
45
|
post_install_message:
|