Permalink
Browse files

[dm-types] Refactored types

* Changed usage of size() to length()
* Minor formatting change
* Removed Serial type which is included in dm-core
  • Loading branch information...
1 parent 36db690 commit 4aad0d722be1ce105cb56a2e7af2217e6f43ed81 @dkubb dkubb committed Jun 23, 2009
View
@@ -15,7 +15,6 @@ lib/dm-types/flag.rb
lib/dm-types/ip_address.rb
lib/dm-types/json.rb
lib/dm-types/regexp.rb
-lib/dm-types/serial.rb
lib/dm-types/slug.rb
lib/dm-types/uri.rb
lib/dm-types/uuid.rb
@@ -4,7 +4,7 @@ module DataMapper
module Types
class BCryptHash < DataMapper::Type
primitive String
- size 60
+ length 60
def self.load(value, property)
typecast(value, property)
View
@@ -14,24 +14,23 @@ module DataMapper
module Types
class Csv < DataMapper::Type
primitive Text
- lazy true
+ lazy true
def self.load(value, property)
case value
- when String then CSV.parse(value)
- when Array then value
- else nil
+ when String then CSV.parse(value)
+ when Array then value
+ else
+ nil
end
end
def self.dump(value, property)
case value
- when Array then
- CSV.generate do |csv|
- value.each { |row| csv << row }
- end
- when String then value
- else nil
+ when Array then CSV.generate { |csv| value.each { |row| csv << row } }
+ when String then value
+ else
+ nil
end
end
end # class Csv
View
@@ -4,8 +4,7 @@ class EpochTime < DataMapper::Type
primitive Integer
def self.load(value, property)
- case value
- when Integer
+ if value.kind_of?(Integer)
Time.at(value)
else
value
@@ -14,12 +13,8 @@ def self.load(value, property)
def self.dump(value, property)
case value
- when Integer
- value
- when Time
- value.to_i
- when DateTime
- Time.parse(value.to_s).to_i
+ when Integer, Time then value.to_i
+ when DateTime then value.to_time.to_i
end
end
end # class EpochTime
@@ -5,7 +5,7 @@ module DataMapper
module Types
class FilePath < DataMapper::Type
primitive String
- size 255
+ length 255
def self.load(value, property)
if value.blank?
@@ -4,7 +4,7 @@ module DataMapper
module Types
class IPAddress < DataMapper::Type
primitive String
- size 16
+ length 16
def self.load(value, property)
if value.nil?
View
@@ -11,8 +11,8 @@ module DataMapper
module Types
class Json < DataMapper::Type
primitive String
- size 65535
- lazy true
+ length 65535
+ lazy true
def self.load(value, property)
if value.nil?
View
@@ -8,12 +8,11 @@ def self.load(value, property)
end
def self.dump(value, property)
- return nil if value.nil?
- value.source
+ value.source unless value.nil?
end
def self.typecast(value, property)
- value.kind_of?(::Regexp) ? value : load(value, property)
+ load(value, property)
end
end
end
View
@@ -1,8 +0,0 @@
-module DataMapper
- module Types
- class Serial < DataMapper::Type
- primitive Integer
- serial true
- end # class Serial
- end # module Types
-end # module DataMapper
View
@@ -4,7 +4,7 @@ module DataMapper
module Types
class Slug < DataMapper::Type
primitive String
- size 65535
+ length 65535
def self.load(value, property)
value
View
@@ -39,20 +39,22 @@ module Types
#
class UUID < DataMapper::Type
primitive String
- size 36
+ length 36
def self.load(value, property)
- return nil if value.nil?
- UUIDTools::UUID.parse(value)
+ UUIDTools::UUID.parse(value) unless value.nil?
end
def self.dump(value, property)
- return nil if value.nil?
- value.to_s
+ value.to_s unless value.nil?
end
def self.typecast(value, property)
- value.kind_of?(UUIDTools::UUID) ? value : load(value, property)
+ if value.kind_of?(UUIDTools::UUID)
+ value
+ else
+ load(value, property)
+ end
end
end
end
View
@@ -4,8 +4,8 @@ module DataMapper
module Types
class Yaml < DataMapper::Type
primitive String
- size 65535
- lazy true
+ length 65535
+ lazy true
def self.load(value, property)
if value.nil?

0 comments on commit 4aad0d7

Please sign in to comment.