dm-types 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +18 -19
  3. data/Rakefile +3 -3
  4. data/VERSION +1 -1
  5. data/dm-types.gemspec +16 -11
  6. data/lib/dm-types/enum.rb +2 -13
  7. data/lib/dm-types/flag.rb +2 -13
  8. data/lib/dm-types/json.rb +1 -1
  9. data/lib/dm-types/paranoid_boolean.rb +1 -1
  10. data/lib/dm-types/paranoid_datetime.rb +1 -1
  11. data/lib/dm-types/support/flags.rb +41 -0
  12. data/lib/dm-types/uri.rb +2 -3
  13. data/lib/dm-types/uuid.rb +4 -0
  14. data/spec/fixtures/article.rb +23 -25
  15. data/spec/fixtures/bookmark.rb +15 -17
  16. data/spec/fixtures/invention.rb +2 -4
  17. data/spec/fixtures/network_node.rb +34 -36
  18. data/spec/fixtures/person.rb +15 -18
  19. data/spec/fixtures/software_package.rb +23 -25
  20. data/spec/fixtures/ticket.rb +15 -17
  21. data/spec/fixtures/tshirt.rb +2 -4
  22. data/spec/integration/bcrypt_hash_spec.rb +4 -4
  23. data/spec/integration/comma_separated_list_spec.rb +2 -2
  24. data/spec/integration/enum_spec.rb +7 -7
  25. data/spec/integration/file_path_spec.rb +7 -7
  26. data/spec/integration/flag_spec.rb +3 -3
  27. data/spec/integration/ip_address_spec.rb +2 -2
  28. data/spec/integration/json_spec.rb +2 -2
  29. data/spec/integration/slug_spec.rb +5 -5
  30. data/spec/integration/uri_spec.rb +9 -9
  31. data/spec/integration/uuid_spec.rb +6 -6
  32. data/spec/integration/yaml_spec.rb +3 -3
  33. data/spec/shared/flags_shared_spec.rb +37 -0
  34. data/spec/spec_helper.rb +2 -0
  35. data/spec/unit/bcrypt_hash_spec.rb +2 -2
  36. data/spec/unit/csv_spec.rb +1 -1
  37. data/spec/unit/enum_spec.rb +4 -0
  38. data/spec/unit/epoch_time_spec.rb +1 -1
  39. data/spec/unit/file_path_spec.rb +1 -1
  40. data/spec/unit/flag_spec.rb +6 -2
  41. data/spec/unit/ip_address_spec.rb +1 -1
  42. data/spec/unit/json_spec.rb +2 -2
  43. data/spec/unit/regexp_spec.rb +1 -1
  44. data/spec/unit/uri_spec.rb +1 -1
  45. data/spec/unit/uuid_spec.rb +25 -0
  46. data/spec/unit/yaml_spec.rb +2 -2
  47. data/tasks/local_gemfile.rake +5 -7
  48. metadata +13 -19
data/.gitignore CHANGED
@@ -31,6 +31,7 @@ measurements
31
31
  .bundle
32
32
  Gemfile.local
33
33
  Gemfile.lock
34
+ Gemfile.local.lock
34
35
 
35
36
  ## PROJECT::SPECIFIC
36
37
  spec/db/
data/Gemfile CHANGED
@@ -71,14 +71,14 @@
71
71
  source 'http://rubygems.org'
72
72
 
73
73
  DATAMAPPER = 'git://github.com/datamapper'
74
- DM_VERSION = '~> 1.0.0'
74
+ DM_VERSION = '~> 1.0.1'
75
75
 
76
76
  group :runtime do # Runtime dependencies (as in the gemspec)
77
77
 
78
78
  if ENV['EXTLIB']
79
- gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
80
  else
81
- gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
81
+ gem 'activesupport', '~> 3.0.0', :git => 'git://github.com/rails/rails.git', :branch => '3-0-stable', :require => nil
82
82
  end
83
83
 
84
84
  gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
@@ -94,7 +94,7 @@ group(:development) do # Development dependencies (as in the gemspec)
94
94
  gem 'dm-validations', DM_VERSION, :git => "#{DATAMAPPER}/dm-validations.git"
95
95
 
96
96
  gem 'rake', '~> 0.8.7'
97
- gem 'rspec', '~> 1.3'
97
+ gem 'rspec', '~> 1.3', :git => 'git://github.com/snusnu/rspec', :branch => 'heckle_fix_plus_gemfile'
98
98
  gem 'jeweler', '~> 1.4'
99
99
 
100
100
  end
@@ -113,32 +113,31 @@ end
113
113
  group :datamapper do # We need this because we want to pin these dependencies to their git master sources
114
114
 
115
115
  adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
116
- adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
116
+ adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
117
117
 
118
- unless adapters.empty?
118
+ DO_VERSION = '~> 0.10.2'
119
+ DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
119
120
 
120
- DO_VERSION = '~> 0.10.3'
121
- DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
121
+ if (do_adapters = DM_DO_ADAPTERS & adapters).any?
122
+ options = {}
123
+ options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
122
124
 
123
- gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
125
+ gem 'data_objects', DO_VERSION, options.dup
124
126
 
125
- adapters.each do |adapter|
126
- if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
127
- adapter = 'sqlite3' if adapter == 'sqlite'
128
- gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
129
- end
127
+ do_adapters.each do |adapter|
128
+ adapter = 'sqlite3' if adapter == 'sqlite'
129
+ gem "do_#{adapter}", DO_VERSION, options.dup
130
130
  end
131
131
 
132
132
  gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
133
+ end
133
134
 
134
- adapters.each do |adapter|
135
- gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
136
- end
137
-
135
+ adapters.each do |adapter|
136
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
138
137
  end
139
138
 
140
139
  plugins = ENV['PLUGINS'] || ENV['PLUGIN']
141
- plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
140
+ plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
142
141
 
143
142
  plugins.each do |plugin|
144
143
  gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
data/Rakefile CHANGED
@@ -15,14 +15,14 @@ begin
15
15
 
16
16
  gem.rubyforge_project = 'datamapper'
17
17
 
18
- gem.add_dependency 'dm-core', '~> 1.0.0'
18
+ gem.add_dependency 'dm-core', '~> 1.0.1'
19
19
  gem.add_dependency 'fastercsv', '~> 1.5.3'
20
- gem.add_dependency 'json_pure', '~> 1.4.3'
20
+ gem.add_dependency 'json_pure', '~> 1.4'
21
21
  gem.add_dependency 'uuidtools', '~> 2.1.1'
22
22
  gem.add_dependency 'stringex', '~> 1.1.0'
23
23
 
24
24
  gem.add_development_dependency 'rspec', '~> 1.3'
25
- gem.add_development_dependency 'dm-validations', '~> 1.0.0'
25
+ gem.add_development_dependency 'dm-validations', '~> 1.0.1'
26
26
  end
27
27
 
28
28
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
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.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Kubb"]
12
- s.date = %q{2010-06-08}
12
+ s.date = %q{2010-09-07}
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 = [
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
39
39
  "lib/dm-types/paranoid_datetime.rb",
40
40
  "lib/dm-types/regexp.rb",
41
41
  "lib/dm-types/slug.rb",
42
+ "lib/dm-types/support/flags.rb",
42
43
  "lib/dm-types/uri.rb",
43
44
  "lib/dm-types/uuid.rb",
44
45
  "lib/dm-types/yaml.rb",
@@ -62,6 +63,7 @@ Gem::Specification.new do |s|
62
63
  "spec/integration/uuid_spec.rb",
63
64
  "spec/integration/yaml_spec.rb",
64
65
  "spec/rcov.opts",
66
+ "spec/shared/flags_shared_spec.rb",
65
67
  "spec/shared/identity_function_group.rb",
66
68
  "spec/spec.opts",
67
69
  "spec/spec_helper.rb",
@@ -77,6 +79,7 @@ Gem::Specification.new do |s|
77
79
  "spec/unit/paranoid_datetime_spec.rb",
78
80
  "spec/unit/regexp_spec.rb",
79
81
  "spec/unit/uri_spec.rb",
82
+ "spec/unit/uuid_spec.rb",
80
83
  "spec/unit/yaml_spec.rb",
81
84
  "tasks/ci.rake",
82
85
  "tasks/local_gemfile.rake",
@@ -111,6 +114,7 @@ Gem::Specification.new do |s|
111
114
  "spec/integration/uri_spec.rb",
112
115
  "spec/integration/uuid_spec.rb",
113
116
  "spec/integration/yaml_spec.rb",
117
+ "spec/shared/flags_shared_spec.rb",
114
118
  "spec/shared/identity_function_group.rb",
115
119
  "spec/spec_helper.rb",
116
120
  "spec/unit/bcrypt_hash_spec.rb",
@@ -125,6 +129,7 @@ Gem::Specification.new do |s|
125
129
  "spec/unit/paranoid_datetime_spec.rb",
126
130
  "spec/unit/regexp_spec.rb",
127
131
  "spec/unit/uri_spec.rb",
132
+ "spec/unit/uuid_spec.rb",
128
133
  "spec/unit/yaml_spec.rb"
129
134
  ]
130
135
 
@@ -133,30 +138,30 @@ Gem::Specification.new do |s|
133
138
  s.specification_version = 3
134
139
 
135
140
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
136
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0"])
141
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.1"])
137
142
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.3"])
138
- s.add_runtime_dependency(%q<json_pure>, ["~> 1.4.3"])
143
+ s.add_runtime_dependency(%q<json_pure>, ["~> 1.4"])
139
144
  s.add_runtime_dependency(%q<uuidtools>, ["~> 2.1.1"])
140
145
  s.add_runtime_dependency(%q<stringex>, ["~> 1.1.0"])
141
146
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
142
- s.add_development_dependency(%q<dm-validations>, ["~> 1.0.0"])
147
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.0.1"])
143
148
  else
144
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
149
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
145
150
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
146
- s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
151
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
147
152
  s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
148
153
  s.add_dependency(%q<stringex>, ["~> 1.1.0"])
149
154
  s.add_dependency(%q<rspec>, ["~> 1.3"])
150
- s.add_dependency(%q<dm-validations>, ["~> 1.0.0"])
155
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.1"])
151
156
  end
152
157
  else
153
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
158
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
154
159
  s.add_dependency(%q<fastercsv>, ["~> 1.5.3"])
155
- s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
160
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
156
161
  s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
157
162
  s.add_dependency(%q<stringex>, ["~> 1.1.0"])
158
163
  s.add_dependency(%q<rspec>, ["~> 1.3"])
159
- s.add_dependency(%q<dm-validations>, ["~> 1.0.0"])
164
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.1"])
160
165
  end
161
166
  end
162
167
 
data/lib/dm-types/enum.rb CHANGED
@@ -1,17 +1,10 @@
1
1
  require 'dm-core'
2
+ require 'dm-types/support/flags'
2
3
 
3
4
  module DataMapper
4
5
  class Property
5
6
  class Enum < Integer
6
- accept_options :flags
7
-
8
- attr_reader :flag_map
9
-
10
- def self.[](*values)
11
- klass = ::Class.new(self)
12
- klass.flags(values)
13
- klass
14
- end
7
+ include Flags
15
8
 
16
9
  def initialize(model, name, options = {}, type = nil)
17
10
  super
@@ -33,10 +26,6 @@ module DataMapper
33
26
  end
34
27
  end
35
28
 
36
- def custom?
37
- true
38
- end
39
-
40
29
  def load(value)
41
30
  flag_map[value]
42
31
  end
data/lib/dm-types/flag.rb CHANGED
@@ -1,17 +1,10 @@
1
1
  require 'dm-core'
2
+ require 'dm-types/support/flags'
2
3
 
3
4
  module DataMapper
4
5
  class Property
5
6
  class Flag < Integer
6
- accept_options :flags
7
-
8
- attr_reader :flag_map
9
-
10
- def self.[](*values)
11
- klass = ::Class.new(self)
12
- klass.flags(values)
13
- klass
14
- end
7
+ include Flags
15
8
 
16
9
  def initialize(model, name, options = {}, type = nil)
17
10
  super
@@ -24,10 +17,6 @@ module DataMapper
24
17
  end
25
18
  end
26
19
 
27
- def custom?
28
- true
29
- end
30
-
31
20
  def load(value)
32
21
  return [] if value.nil? || value <= 0
33
22
 
data/lib/dm-types/json.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'dm-core'
2
- require 'json'
2
+ require 'json/pure'
3
3
 
4
4
  module DataMapper
5
5
  class Property
@@ -11,7 +11,7 @@ module DataMapper
11
11
  property_name = name.inspect
12
12
 
13
13
  model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
14
- include Paranoid::Base
14
+ include DataMapper::Types::Paranoid::Base
15
15
 
16
16
  set_paranoid_property(#{property_name}) { true }
17
17
 
@@ -10,7 +10,7 @@ module DataMapper
10
10
  property_name = name.inspect
11
11
 
12
12
  model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
13
- include Paranoid::Base
13
+ include DataMapper::Types::Paranoid::Base
14
14
 
15
15
  set_paranoid_property(#{property_name}) { ::DateTime.now }
16
16
 
@@ -0,0 +1,41 @@
1
+ module DataMapper
2
+ class Property
3
+ module Flags
4
+ def self.included(base)
5
+ base.class_eval <<-RUBY, __FILE__, __LINE__ + 1
6
+ extend DataMapper::Property::Flags::ClassMethods
7
+
8
+ accept_options :flags
9
+ attr_reader :flag_map
10
+
11
+ class << self
12
+ attr_accessor :generated_classes
13
+ end
14
+
15
+ self.generated_classes = {}
16
+ RUBY
17
+ end
18
+
19
+ def custom?
20
+ true
21
+ end
22
+
23
+ module ClassMethods
24
+ # TODO: document
25
+ # @api public
26
+ def [](*values)
27
+ if klass = generated_classes[values.flatten]
28
+ klass
29
+ else
30
+ klass = ::Class.new(self)
31
+ klass.flags(values)
32
+
33
+ generated_classes[values.flatten] = klass
34
+
35
+ klass
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/dm-types/uri.rb CHANGED
@@ -4,6 +4,8 @@ require 'dm-core'
4
4
  module DataMapper
5
5
  class Property
6
6
  class URI < String
7
+ # Maximum length chosen based on recommendation:
8
+ # http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-an-url
7
9
  length 2000
8
10
 
9
11
  def custom?
@@ -18,9 +20,6 @@ module DataMapper
18
20
  super || primitive?(value) || value.kind_of?(::String)
19
21
  end
20
22
 
21
- # Maximum length chosen based on recommendation:
22
- # http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-an-url
23
-
24
23
  def load(value)
25
24
  Addressable::URI.parse(value)
26
25
  end
data/lib/dm-types/uuid.rb CHANGED
@@ -48,6 +48,10 @@ module DataMapper
48
48
  value.kind_of?(UUIDTools::UUID)
49
49
  end
50
50
 
51
+ def valid?(value, negated = false)
52
+ super || dump(value).kind_of?(::String)
53
+ end
54
+
51
55
  def dump(value)
52
56
  value.to_s unless value.nil?
53
57
  end
@@ -1,37 +1,35 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
4
3
 
5
- class Article
6
- #
7
- # Behaviors
8
- #
4
+ class Article
5
+ #
6
+ # Behaviors
7
+ #
9
8
 
10
- include ::DataMapper::Resource
9
+ include ::DataMapper::Resource
11
10
 
12
- #
13
- # Properties
14
- #
11
+ #
12
+ # Properties
13
+ #
15
14
 
16
- property :id, Serial
15
+ property :id, Serial
17
16
 
18
- property :title, String, :length => 255
19
- property :body, Text
17
+ property :title, String, :length => 255
18
+ property :body, Text
20
19
 
21
- property :created_at, DateTime
22
- property :updated_at, DateTime
23
- property :published_at, DateTime
20
+ property :created_at, DateTime
21
+ property :updated_at, DateTime
22
+ property :published_at, DateTime
24
23
 
25
- property :slug, Slug
24
+ property :slug, Slug
26
25
 
27
- #
28
- # Hooks
29
- #
26
+ #
27
+ # Hooks
28
+ #
30
29
 
31
- before :valid? do
32
- self.slug = self.title
33
- end
34
- end # Article
35
- end
30
+ before :valid? do
31
+ self.slug = self.title
32
+ end
33
+ end # Article
36
34
  end
37
35
  end
@@ -1,25 +1,23 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
4
3
 
5
- class Bookmark
6
- #
7
- # Behaviors
8
- #
4
+ class Bookmark
5
+ #
6
+ # Behaviors
7
+ #
9
8
 
10
- include ::DataMapper::Resource
9
+ include ::DataMapper::Resource
11
10
 
12
- #
13
- # Properties
14
- #
11
+ #
12
+ # Properties
13
+ #
15
14
 
16
- property :id, Serial
15
+ property :id, Serial
17
16
 
18
- property :title, String, :length => 255
19
- property :shared, Boolean
20
- property :uri, URI
21
- property :tags, Yaml
22
- end # Bookmark
23
- end
17
+ property :title, String, :length => 255
18
+ property :shared, Boolean
19
+ property :uri, URI
20
+ property :tags, Yaml
21
+ end # Bookmark
24
22
  end
25
23
  end