dm-types 1.1.0.rc2 → 1.1.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ source 'http://rubygems.org'
5
5
  SOURCE = ENV.fetch('SOURCE', :git).to_sym
6
6
  REPO_POSTFIX = SOURCE == :path ? '' : '.git'
7
7
  DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
8
- DM_VERSION = '~> 1.1.0.rc2'
8
+ DM_VERSION = '~> 1.1.0.rc3'
9
9
  DO_VERSION = '~> 0.10.2'
10
10
  DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
11
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0.rc2
1
+ 1.1.0.rc3
data/dm-types.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-types}
8
- s.version = "1.1.0.rc2"
8
+ s.version = "1.1.0.rc3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Kubb"]
12
- s.date = %q{2011-03-01}
12
+ s.date = %q{2011-03-10}
13
13
  s.description = %q{DataMapper plugin providing extra data types}
14
14
  s.email = %q{dan.kubb [a] gmail [d] com}
15
15
  s.extra_rdoc_files = [
@@ -87,7 +87,7 @@ Gem::Specification.new do |s|
87
87
  s.homepage = %q{http://github.com/datamapper/dm-types}
88
88
  s.require_paths = ["lib"]
89
89
  s.rubyforge_project = %q{datamapper}
90
- s.rubygems_version = %q{1.5.2}
90
+ s.rubygems_version = %q{1.6.2}
91
91
  s.summary = %q{DataMapper plugin providing extra data types}
92
92
  s.test_files = [
93
93
  "spec/fixtures/article.rb",
@@ -133,35 +133,35 @@ Gem::Specification.new do |s|
133
133
 
134
134
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
135
135
  s.add_runtime_dependency(%q<bcrypt-ruby>, ["~> 2.1.4"])
136
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
136
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
137
137
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.4"])
138
138
  s.add_runtime_dependency(%q<json>, ["~> 1.4.6"])
139
139
  s.add_runtime_dependency(%q<stringex>, ["~> 1.2.0"])
140
140
  s.add_runtime_dependency(%q<uuidtools>, ["~> 2.1.2"])
141
- s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0.rc2"])
141
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
142
142
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
143
143
  s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
144
144
  s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
145
145
  else
146
146
  s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.4"])
147
- s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
147
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
148
148
  s.add_dependency(%q<fastercsv>, ["~> 1.5.4"])
149
149
  s.add_dependency(%q<json>, ["~> 1.4.6"])
150
150
  s.add_dependency(%q<stringex>, ["~> 1.2.0"])
151
151
  s.add_dependency(%q<uuidtools>, ["~> 2.1.2"])
152
- s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc2"])
152
+ s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
153
153
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
154
154
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
155
155
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
156
156
  end
157
157
  else
158
158
  s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.4"])
159
- s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc2"])
159
+ s.add_dependency(%q<dm-core>, ["~> 1.1.0.rc3"])
160
160
  s.add_dependency(%q<fastercsv>, ["~> 1.5.4"])
161
161
  s.add_dependency(%q<json>, ["~> 1.4.6"])
162
162
  s.add_dependency(%q<stringex>, ["~> 1.2.0"])
163
163
  s.add_dependency(%q<uuidtools>, ["~> 2.1.2"])
164
- s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc2"])
164
+ s.add_dependency(%q<dm-validations>, ["~> 1.1.0.rc3"])
165
165
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
166
166
  s.add_dependency(%q<rake>, ["~> 0.8.7"])
167
167
  s.add_dependency(%q<rspec>, ["~> 1.3.1"])
data/lib/dm-types.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  require 'dm-core'
2
2
 
3
- begin
4
- require 'active_support/core_ext/date_time/conversions'
5
- rescue LoadError
6
- require 'extlib/datetime'
7
- end
8
-
9
3
  module DataMapper
10
4
  class Property
11
5
  autoload :CommaSeparatedList, 'dm-types/comma_separated_list'
@@ -4,6 +4,7 @@ require 'bcrypt'
4
4
  module DataMapper
5
5
  class Property
6
6
  class BCryptHash < String
7
+
7
8
  length 60
8
9
 
9
10
  def primitive?(value)
@@ -11,9 +12,7 @@ module DataMapper
11
12
  end
12
13
 
13
14
  def load(value)
14
- if value.nil?
15
- nil
16
- else
15
+ unless value.nil?
17
16
  begin
18
17
  primitive?(value) ? value : BCrypt::Password.new(value)
19
18
  rescue BCrypt::Errors::InvalidHash
@@ -29,6 +28,7 @@ module DataMapper
29
28
  def typecast_to_primitive(value)
30
29
  load(value)
31
30
  end
31
+
32
32
  end # class BCryptHash
33
33
  end # class Property
34
34
  end # module DataMapper
@@ -4,23 +4,26 @@ require 'dm-types/yaml'
4
4
  module DataMapper
5
5
  class Property
6
6
  class CommaSeparatedList < Yaml
7
+
7
8
  def dump(value)
8
9
  if value.nil?
9
10
  nil
10
11
  elsif value.kind_of?(::Array)
11
12
  super(value)
12
13
  elsif value.kind_of?(::String)
13
- v = (value || "").split(",").
14
- compact.
15
- map { |i| i.downcase.strip }.
16
- reject { |i| i.blank? }.
17
- uniq
14
+ v = []
15
+
16
+ value.split(',').each do |element|
17
+ element.strip!
18
+ v << element unless element.empty?
19
+ end
20
+
18
21
  super(v)
19
22
  else
20
23
  raise ArgumentError, "+value+ of CommaSeparatedList must be a string, an array or nil, but given #{value.inspect}"
21
24
  end
22
25
  end # dump
23
- end # CommaSeparatedList
24
26
 
27
+ end # CommaSeparatedList
25
28
  end # Property
26
29
  end # DataMapper
data/lib/dm-types/csv.rb CHANGED
@@ -10,27 +10,26 @@ end
10
10
  module DataMapper
11
11
  class Property
12
12
  class Csv < Text
13
+
13
14
  def primitive?(value)
14
15
  super || value.kind_of?(::Array)
15
16
  end
16
17
 
17
18
  def load(value)
18
19
  case value
19
- when ::String then CSV.parse(value)
20
- when ::Array then value
21
- else
22
- nil
20
+ when ::String then CSV.parse(value)
21
+ when ::Array then value
23
22
  end
24
23
  end
25
24
 
26
25
  def dump(value)
27
26
  case value
28
- when ::Array then CSV.generate { |csv| value.each { |row| csv << row } }
27
+ when ::Array
28
+ CSV.generate { |csv| value.each { |row| csv << row } }
29
29
  when ::String then value
30
- else
31
- nil
32
30
  end
33
31
  end
32
+
34
33
  end # class Csv
35
34
  end # class Property
36
35
  end # module DataMapper
data/lib/dm-types/enum.rb CHANGED
@@ -4,6 +4,7 @@ require 'dm-types/support/flags'
4
4
  module DataMapper
5
5
  class Property
6
6
  class Enum < Integer
7
+
7
8
  include Flags
8
9
 
9
10
  def initialize(model, name, options = {})
@@ -46,6 +47,7 @@ module DataMapper
46
47
  else value
47
48
  end
48
49
  end
50
+
49
51
  end # class Enum
50
52
  end # class Property
51
53
  end # module DataMapper
@@ -1,18 +1,12 @@
1
1
  require 'dm-core'
2
2
 
3
- begin
4
- # provide Time#utc_time for DateTime#to_time in AS
5
- require 'active_support/core_ext/time/calculations'
6
- rescue LoadError
7
- # do nothing, extlib is being used and does not require this method
8
- end
9
-
10
3
  module DataMapper
11
4
  class Property
12
5
  class EpochTime < Integer
6
+
13
7
  def load(value)
14
- if value.kind_of?(::Integer)
15
- ::Time.at(value)
8
+ if value.kind_of?(::Numeric)
9
+ ::Time.at(value.to_i)
16
10
  else
17
11
  value
18
12
  end
@@ -20,10 +14,18 @@ module DataMapper
20
14
 
21
15
  def dump(value)
22
16
  case value
23
- when ::Integer, ::Time then value.to_i
24
- when ::DateTime then value.to_time.to_i
17
+ when ::Numeric, ::Time then value.to_i
18
+ when ::DateTime then datetime_to_time(value).to_i
25
19
  end
26
20
  end
21
+
22
+ private
23
+
24
+ def datetime_to_time(datetime)
25
+ utc = datetime.new_offset(0)
26
+ ::Time.utc(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec)
27
+ end
28
+
27
29
  end # class EpochTime
28
30
  end # class Property
29
31
  end # module DataMapper
@@ -4,6 +4,7 @@ require 'dm-core'
4
4
  module DataMapper
5
5
  class Property
6
6
  class FilePath < String
7
+
7
8
  length 255
8
9
 
9
10
  def primitive?(value)
@@ -15,21 +16,17 @@ module DataMapper
15
16
  end
16
17
 
17
18
  def load(value)
18
- if value.blank?
19
- nil
20
- else
21
- Pathname.new(value)
22
- end
19
+ Pathname.new(value) unless DataMapper::Ext.blank?(value)
23
20
  end
24
21
 
25
22
  def dump(value)
26
- return nil if value.blank?
27
- value.to_s
23
+ value.to_s unless DataMapper::Ext.blank?(value)
28
24
  end
29
25
 
30
26
  def typecast_to_primitive(value)
31
27
  load(value)
32
28
  end
29
+
33
30
  end # class FilePath
34
31
  end # class Property
35
32
  end # module DataMapper
data/lib/dm-types/flag.rb CHANGED
@@ -4,6 +4,7 @@ require 'dm-types/support/flags'
4
4
  module DataMapper
5
5
  class Property
6
6
  class Flag < Integer
7
+
7
8
  include Flags
8
9
 
9
10
  def initialize(model, name, options = {})
@@ -34,18 +35,29 @@ module DataMapper
34
35
  end
35
36
 
36
37
  def dump(value)
37
- return if value.nil?
38
- flags = Array(value).map { |flag| flag.to_sym }.flatten.uniq
39
- flag_map.invert.values_at(*flags).compact.inject(0) { |sum, i| sum += 1 << i }
38
+ unless value.nil?
39
+ flags = Array(value).map { |flag| flag.to_sym }
40
+ flags.uniq!
41
+
42
+ flag = 0
43
+
44
+ flag_map.invert.values_at(*flags).each do |i|
45
+ next if i.nil?
46
+ flag += (1 << i)
47
+ end
48
+
49
+ flag
50
+ end
40
51
  end
41
52
 
42
53
  def typecast(value)
43
54
  case value
44
- when nil then nil
45
- when ::Array then value.map {|v| v.to_sym}
55
+ when nil then nil
56
+ when ::Array then value.map { |v| v.to_sym }
46
57
  else [value.to_sym]
47
58
  end
48
59
  end
60
+
49
61
  end # class Flag
50
62
  end # class Property
51
63
  end # module DataMapper
@@ -4,6 +4,7 @@ require 'dm-core'
4
4
  module DataMapper
5
5
  class Property
6
6
  class IPAddress < String
7
+
7
8
  length 39
8
9
 
9
10
  def primitive?(value)
@@ -17,23 +18,25 @@ module DataMapper
17
18
  def load(value)
18
19
  if value.nil?
19
20
  nil
20
- elsif value.is_a?(::String) && !value.empty?
21
- IPAddr.new(value)
22
- elsif value.is_a?(::String) && value.empty?
23
- IPAddr.new("0.0.0.0")
21
+ elsif value.is_a?(::String)
22
+ unless value.empty?
23
+ IPAddr.new(value)
24
+ else
25
+ IPAddr.new("0.0.0.0")
26
+ end
24
27
  else
25
28
  raise ArgumentError.new("+value+ must be nil or a String")
26
29
  end
27
30
  end
28
31
 
29
32
  def dump(value)
30
- return nil if value.nil?
31
- value.to_s
33
+ value.to_s unless value.nil?
32
34
  end
33
35
 
34
36
  def typecast_to_primitive(value)
35
37
  load(value)
36
38
  end
39
+
37
40
  end # class IPAddress
38
41
  end # module Property
39
42
  end # module DataMapper
data/lib/dm-types/json.rb CHANGED
@@ -4,6 +4,7 @@ require 'json' unless defined? JSON
4
4
  module DataMapper
5
5
  class Property
6
6
  class Json < Text
7
+
7
8
  def custom?
8
9
  true
9
10
  end
@@ -37,7 +38,10 @@ module DataMapper
37
38
  def typecast_to_primitive(value)
38
39
  ::JSON.load(value.to_s)
39
40
  end
41
+
40
42
  end # class Json
43
+
41
44
  JSON = Json
45
+
42
46
  end # class Property
43
47
  end # module DataMapper
@@ -3,6 +3,7 @@ require 'dm-core'
3
3
  module DataMapper
4
4
  class Property
5
5
  class Regexp < String
6
+
6
7
  def load(value)
7
8
  ::Regexp.new(value) unless value.nil?
8
9
  end
@@ -14,6 +15,7 @@ module DataMapper
14
15
  def typecast(value)
15
16
  load(value)
16
17
  end
18
+
17
19
  end
18
20
  end
19
21
  end
data/lib/dm-types/slug.rb CHANGED
@@ -4,15 +4,16 @@ require 'stringex'
4
4
  module DataMapper
5
5
  class Property
6
6
  class Slug < String
7
+
7
8
  # Maximum length chosen because URI type is limited to 2000
8
9
  # characters, and a slug is a component of a URI, so it should
9
10
  # not exceed the maximum URI length either.
10
11
  length 2000
11
12
 
12
13
  def typecast(value)
13
- return if value.nil?
14
-
15
- if value.respond_to?(:to_str)
14
+ if value.nil?
15
+ nil
16
+ elsif value.respond_to?(:to_str)
16
17
  escape(value.to_str)
17
18
  else
18
19
  raise ArgumentError, '+value+ must be nil or respond to #to_str'
@@ -22,6 +23,7 @@ module DataMapper
22
23
  def escape(string)
23
24
  string.to_url
24
25
  end
26
+
25
27
  end # class Slug
26
28
  end # class Property
27
29
  end # module DataMapper
data/lib/dm-types/uri.rb CHANGED
@@ -4,6 +4,7 @@ require 'dm-core'
4
4
  module DataMapper
5
5
  class Property
6
6
  class URI < String
7
+
7
8
  # Maximum length chosen based on recommendation:
8
9
  # http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-an-url
9
10
  length 2000
@@ -31,6 +32,7 @@ module DataMapper
31
32
  def typecast_to_primitive(value)
32
33
  load(value)
33
34
  end
35
+
34
36
  end # class URI
35
37
  end # class Property
36
38
  end # module DataMapper
data/lib/dm-types/uuid.rb CHANGED
@@ -39,6 +39,7 @@ module DataMapper
39
39
  # -- benburkert Nov 15, 08
40
40
  #
41
41
  class UUID < String
42
+
42
43
  length 36
43
44
 
44
45
  # We need to override this method otherwise typecast_to_primitive won't be called.
@@ -67,6 +68,7 @@ module DataMapper
67
68
  def typecast_to_primitive(value)
68
69
  load(value)
69
70
  end
71
+
70
72
  end
71
73
  end
72
74
  end
data/lib/dm-types/yaml.rb CHANGED
@@ -4,6 +4,7 @@ require 'dm-core'
4
4
  module DataMapper
5
5
  class Property
6
6
  class Yaml < Text
7
+
7
8
  def custom?
8
9
  true
9
10
  end
@@ -31,6 +32,7 @@ module DataMapper
31
32
  def typecast(value)
32
33
  value
33
34
  end
35
+
34
36
  end # class Yaml
35
37
  end # class Property
36
38
  end # module DataMapper
@@ -78,11 +78,7 @@ try_spec do
78
78
  end
79
79
 
80
80
  it 'has blank entries removed' do
81
- @resource.interests.any? { |i| i.blank? }.should be(false)
82
- end
83
-
84
- it 'has duplicates removed' do
85
- @resource.interests.select { |i| i == 'fire' }.size.should == 1
81
+ @resource.interests.any? { |i| DataMapper::Ext.blank?(i) }.should be(false)
86
82
  end
87
83
  end
88
84
  end
@@ -64,7 +64,7 @@ try_spec do
64
64
  end
65
65
 
66
66
  it 'has no errors' do
67
- @resource.errors.should be_blank
67
+ @resource.errors.should be_empty
68
68
  end
69
69
  end
70
70
  end
@@ -120,7 +120,7 @@ try_spec do
120
120
  end
121
121
 
122
122
  it 'can be found by uri' do
123
- DataMapper::TypesFixtures::Bookmark.first(:uri => uri).should_not be_blank
123
+ DataMapper::TypesFixtures::Bookmark.first(:uri => uri).should_not be_nil
124
124
  end
125
125
 
126
126
  describe 'when reloaded' do
@@ -1,73 +1,58 @@
1
1
  require 'spec_helper'
2
2
 
3
- try_spec do
4
- describe DataMapper::Property::EpochTime do
5
- before :all do
6
- class ::User
7
- include DataMapper::Resource
8
- property :id, Serial
9
- property :bday, EpochTime
10
- end
11
-
12
- @property = User.properties[:bday]
3
+ describe DataMapper::Property::EpochTime do
4
+ before :all do
5
+ class ::User
6
+ include DataMapper::Resource
7
+
8
+ property :id, Serial
9
+ property :bday, EpochTime
10
+ end
11
+
12
+ @property = User.properties[:bday]
13
+ end
14
+
15
+ describe '#dump' do
16
+ subject { @property.dump(value) }
17
+
18
+ describe 'with a Time instance' do
19
+ let(:value) { Time.now }
20
+
21
+ it { should == value.to_i }
22
+ end
23
+
24
+ describe 'with a DateTime instance' do
25
+ let(:value) { DateTime.now }
26
+
27
+ it { should == Time.parse(value.to_s).to_i }
13
28
  end
14
29
 
15
- describe '.dump' do
16
- describe 'when given Time instance' do
17
- before :all do
18
- @input = Time.now
19
- end
20
-
21
- it 'returns timestamp' do
22
- @property.dump(@input).should == @input.to_i
23
- end
24
- end
25
-
26
- describe 'when given DateTime instance' do
27
- before :all do
28
- @input = DateTime.now
29
- end
30
-
31
- it 'returns timestamp' do
32
- pending 'Does not work with < 1.8.7, see if backports fixes it' if RUBY_VERSION < '1.8.7'
33
- @property.dump(@input).should == Time.parse(@input.to_s).to_i
34
- end
35
- end
36
-
37
- describe 'when given an integer' do
38
- before :all do
39
- @input = Time.now.to_i
40
- end
41
-
42
- it 'returns value as is' do
43
- @property.dump(@input).should == @input
44
- end
45
- end
46
-
47
- describe 'when given nil' do
48
- before :all do
49
- @input = nil
50
- end
51
-
52
- it 'returns value as is' do
53
- @property.dump(@input).should == @input
54
- end
55
- end
30
+ describe 'with a number' do
31
+ let(:value) { Time.now.to_i }
32
+
33
+ it { should == value }
34
+ end
35
+
36
+ describe 'with nil' do
37
+ let(:value) { nil }
38
+
39
+ it { should == value }
40
+ end
41
+ end
42
+
43
+ describe '#load' do
44
+ subject { @property.load(value) }
45
+
46
+ describe 'with a number' do
47
+ let(:value) { Time.now.to_i }
48
+
49
+ it { should == Time.at(value) }
56
50
  end
57
51
 
58
- describe '.load' do
59
- describe 'when value is nil' do
60
- it 'returns nil' do
61
- @property.load(nil).should == nil
62
- end
63
- end
64
-
65
- describe 'when value is an integer' do
66
- it 'returns time object from timestamp' do
67
- t = Time.now.to_i
68
- @property.load(Time.now.to_i).should == Time.at(t)
69
- end
70
- end
52
+ describe 'with nil' do
53
+ let(:value) { nil }
54
+
55
+ it { should == value }
71
56
  end
72
57
  end
73
58
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dm-types
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 1.1.0.rc2
5
+ version: 1.1.0.rc3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Kubb
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 -08:00
13
+ date: 2011-03-10 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: 1.1.0.rc2
34
+ version: 1.1.0.rc3
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: *id002
@@ -86,7 +86,7 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 1.1.0.rc2
89
+ version: 1.1.0.rc3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: *id007
@@ -223,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  requirements: []
224
224
 
225
225
  rubyforge_project: datamapper
226
- rubygems_version: 1.5.2
226
+ rubygems_version: 1.6.2
227
227
  signing_key:
228
228
  specification_version: 3
229
229
  summary: DataMapper plugin providing extra data types