dm-types 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +2 -1
- data/lib/dm-types.rb +1 -1
- data/lib/dm-types/uuid.rb +26 -5
- data/lib/dm-types/version.rb +1 -1
- data/spec/integration/slug_spec.rb +5 -5
- data/spec/integration/uuid_spec.rb +38 -0
- metadata +7 -6
data/Manifest.txt
CHANGED
@@ -13,9 +13,9 @@ lib/dm-types/file_path.rb
|
|
13
13
|
lib/dm-types/flag.rb
|
14
14
|
lib/dm-types/ip_address.rb
|
15
15
|
lib/dm-types/json.rb
|
16
|
-
lib/dm-types/slug.rb
|
17
16
|
lib/dm-types/regexp.rb
|
18
17
|
lib/dm-types/serial.rb
|
18
|
+
lib/dm-types/slug.rb
|
19
19
|
lib/dm-types/uri.rb
|
20
20
|
lib/dm-types/uuid.rb
|
21
21
|
lib/dm-types/version.rb
|
@@ -28,6 +28,7 @@ spec/integration/ip_address_spec.rb
|
|
28
28
|
spec/integration/json_spec.rb
|
29
29
|
spec/integration/slug_spec.rb
|
30
30
|
spec/integration/uri_spec.rb
|
31
|
+
spec/integration/uuid_spec.rb
|
31
32
|
spec/integration/yaml_spec.rb
|
32
33
|
spec/spec.opts
|
33
34
|
spec/spec_helper.rb
|
data/lib/dm-types.rb
CHANGED
data/lib/dm-types/uuid.rb
CHANGED
@@ -17,8 +17,29 @@ module DataMapper
|
|
17
17
|
#
|
18
18
|
# -- Rando Sept 25, 08
|
19
19
|
#
|
20
|
+
# Actually, setting the primitive to "UUID" is not neccessary and causes
|
21
|
+
# a segfault when trying to query uuid's from the database. The primitive
|
22
|
+
# should be a class which has been added to the do driver you are using.
|
23
|
+
# Also, it's only neccessary to add a class to the do drivers to use as a
|
24
|
+
# primitive when a value cannot be represented as a string. A uuid can be
|
25
|
+
# represented as a string, so setting the primitive to String ensures that
|
26
|
+
# the value argument is a String containing the uuid in string form.
|
27
|
+
#
|
28
|
+
# <strike>It is still neccessary to add the UUID entry to the type map for
|
29
|
+
# each different adapter with their respective database primitive.</strike>
|
30
|
+
#
|
31
|
+
# The method that generates the SQL schema from the typemap currently
|
32
|
+
# ignores the size attribute from the type map if the primitive type
|
33
|
+
# is String. The causes the generated SQL statement to contain a size for
|
34
|
+
# a UUID column (e.g. id UUID(50)), which causes a syntax error in postgres.
|
35
|
+
# Until this is resolved, you will have to manually change the column type
|
36
|
+
# to UUID in a migration, if you want to use postgres' built in UUID type.
|
37
|
+
#
|
38
|
+
# -- benburkert Nov 15, 08
|
39
|
+
#
|
20
40
|
class UUID < DataMapper::Type
|
21
|
-
primitive
|
41
|
+
primitive String
|
42
|
+
size 36
|
22
43
|
|
23
44
|
def self.load(value, property)
|
24
45
|
return nil if value.nil?
|
@@ -34,10 +55,10 @@ module DataMapper
|
|
34
55
|
value.kind_of?(::UUID) ? value : load(value, property)
|
35
56
|
end
|
36
57
|
|
37
|
-
|
38
|
-
if defined? DataMapper::Adapters::PostgresAdapter
|
39
|
-
|
40
|
-
end
|
58
|
+
#::DataMapper::Property::TYPES << self
|
59
|
+
#if defined? DataMapper::Adapters::PostgresAdapter
|
60
|
+
# DataMapper::Adapters::PostgresAdapter.type_map.map(self).to('UUID').with(:size => nil)
|
61
|
+
#end
|
41
62
|
end
|
42
63
|
end
|
43
64
|
end
|
data/lib/dm-types/version.rb
CHANGED
@@ -22,25 +22,25 @@ describe DataMapper::Types::Slug do
|
|
22
22
|
|
23
23
|
SlugTest.first.name.should == "new-datamapper-type"
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should find by a slug" do
|
27
27
|
repository(:default) do
|
28
28
|
SlugTest.create(:name => "This Should Be a Slug")
|
29
29
|
end
|
30
30
|
slug = "this-should-be-a-slug"
|
31
|
-
|
31
|
+
|
32
32
|
slugged = SlugTest.first(:name => slug)
|
33
33
|
slugged.should_not be_nil
|
34
34
|
slugged.name.should == slug
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
[
|
38
38
|
["Iñtërnâtiônàlizætiøn", "internationalizaetion" ],
|
39
39
|
["Hello World", "hello-world"],
|
40
40
|
["This is Dan's Blog", "this-is-dans-blog"],
|
41
41
|
["This is My Site, and Blog", "this-is-my-site-and-blog"]
|
42
42
|
].each do |name, slug|
|
43
|
-
|
43
|
+
|
44
44
|
it "should sluggify #{name}" do
|
45
45
|
repository(:default) do
|
46
46
|
SlugTest.create(:name => name)
|
@@ -48,7 +48,7 @@ describe DataMapper::Types::Slug do
|
|
48
48
|
SlugTest.first(:name => slug).should_not be_nil
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
|
53
53
|
|
54
54
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'uuidtools'
|
3
|
+
require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'
|
4
|
+
|
5
|
+
describe DataMapper::Types::UUID do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
class UUIDTest
|
9
|
+
include DataMapper::Resource
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
property :uuid, ::DataMapper::Types::UUID
|
13
|
+
end
|
14
|
+
|
15
|
+
UUIDTest.auto_migrate!
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be settable as a uuid" do
|
19
|
+
u = UUIDTest.create(:uuid => UUID.parse('b0fc632e-d744-4821-afe3-4ea0701859ee'))
|
20
|
+
|
21
|
+
u.uuid.should be_kind_of(UUID)
|
22
|
+
u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be settable as a string" do
|
26
|
+
u = UUIDTest.create(:uuid => 'b0fc632e-d744-4821-afe3-4ea0701859ee')
|
27
|
+
|
28
|
+
u.uuid.should be_kind_of(UUID)
|
29
|
+
u.uuid.to_s.should == 'b0fc632e-d744-4821-afe3-4ea0701859ee'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be allowed to be null" do
|
33
|
+
u = UUIDTest.create()
|
34
|
+
|
35
|
+
u.uuid.should be_nil
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Smoot
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-18 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.
|
23
|
+
version: 0.9.7
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: uuidtools
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 1.
|
43
|
+
version: 1.8.2
|
44
44
|
version:
|
45
45
|
description: DataMapper plugin providing extra data types
|
46
46
|
email:
|
@@ -69,9 +69,9 @@ files:
|
|
69
69
|
- lib/dm-types/flag.rb
|
70
70
|
- lib/dm-types/ip_address.rb
|
71
71
|
- lib/dm-types/json.rb
|
72
|
-
- lib/dm-types/slug.rb
|
73
72
|
- lib/dm-types/regexp.rb
|
74
73
|
- lib/dm-types/serial.rb
|
74
|
+
- lib/dm-types/slug.rb
|
75
75
|
- lib/dm-types/uri.rb
|
76
76
|
- lib/dm-types/uuid.rb
|
77
77
|
- lib/dm-types/version.rb
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- spec/integration/json_spec.rb
|
85
85
|
- spec/integration/slug_spec.rb
|
86
86
|
- spec/integration/uri_spec.rb
|
87
|
+
- spec/integration/uuid_spec.rb
|
87
88
|
- spec/integration/yaml_spec.rb
|
88
89
|
- spec/spec.opts
|
89
90
|
- spec/spec_helper.rb
|
@@ -121,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
122
|
requirements: []
|
122
123
|
|
123
124
|
rubyforge_project: datamapper
|
124
|
-
rubygems_version: 1.
|
125
|
+
rubygems_version: 1.3.1
|
125
126
|
signing_key:
|
126
127
|
specification_version: 2
|
127
128
|
summary: DataMapper plugin providing extra data types
|