dm-types 0.9.8 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -0
- data/lib/dm-types.rb +1 -1
- data/lib/dm-types/enum.rb +4 -4
- data/lib/dm-types/json.rb +3 -6
- data/lib/dm-types/version.rb +1 -1
- metadata +3 -3
data/History.txt
CHANGED
data/lib/dm-types.rb
CHANGED
data/lib/dm-types/enum.rb
CHANGED
@@ -34,8 +34,8 @@ module DataMapper
|
|
34
34
|
|
35
35
|
def self.dump(value, property)
|
36
36
|
case value
|
37
|
-
|
38
|
-
|
37
|
+
when Array then value.collect { |v| self.dump(v, property) }
|
38
|
+
else self.flag_map.invert[value]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -46,7 +46,7 @@ module DataMapper
|
|
46
46
|
when Symbol then value.to_sym
|
47
47
|
when String then value.to_s
|
48
48
|
when Fixnum then value.to_i
|
49
|
-
else
|
49
|
+
else value
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end # class Enum
|
@@ -61,7 +61,7 @@ module DataMapper
|
|
61
61
|
return unless property.options[:auto_validation]
|
62
62
|
|
63
63
|
if property.type.ancestors.include?(Types::Enum)
|
64
|
-
|
64
|
+
validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
data/lib/dm-types/json.rb
CHANGED
@@ -13,14 +13,12 @@ module DataMapper
|
|
13
13
|
elsif value.is_a?(String)
|
14
14
|
::JSON.load(value)
|
15
15
|
else
|
16
|
-
raise ArgumentError
|
16
|
+
raise ArgumentError, '+value+ must be nil or a String'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.dump(value, property)
|
21
|
-
if value.nil?
|
22
|
-
nil
|
23
|
-
elsif value.is_a?(String)
|
21
|
+
if value.nil? || value.is_a?(String)
|
24
22
|
value
|
25
23
|
else
|
26
24
|
::JSON.dump(value)
|
@@ -28,8 +26,7 @@ module DataMapper
|
|
28
26
|
end
|
29
27
|
|
30
28
|
def self.typecast(value, property)
|
31
|
-
|
32
|
-
if value.kind_of?(Array) || value.kind_of?(Hash)
|
29
|
+
if value.nil? || value.kind_of?(Array) || value.kind_of?(Hash)
|
33
30
|
value
|
34
31
|
else
|
35
32
|
::JSON.load(value.to_s)
|
data/lib/dm-types/version.rb
CHANGED
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.9
|
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:
|
12
|
+
date: 2009-01-04 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.9
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: addressable
|