dm-types 0.10.2 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.gitignore +36 -0
  2. data/Gemfile +147 -0
  3. data/Rakefile +7 -8
  4. data/VERSION +1 -1
  5. data/dm-types.gemspec +61 -20
  6. data/lib/dm-types.rb +24 -19
  7. data/lib/dm-types/bcrypt_hash.rb +17 -13
  8. data/lib/dm-types/comma_separated_list.rb +11 -16
  9. data/lib/dm-types/csv.rb +11 -11
  10. data/lib/dm-types/enum.rb +33 -50
  11. data/lib/dm-types/epoch_time.rb +11 -11
  12. data/lib/dm-types/file_path.rb +13 -10
  13. data/lib/dm-types/flag.rb +17 -25
  14. data/lib/dm-types/ip_address.rb +15 -11
  15. data/lib/dm-types/json.rb +17 -14
  16. data/lib/dm-types/paranoid/base.rb +38 -0
  17. data/lib/dm-types/paranoid_boolean.rb +23 -0
  18. data/lib/dm-types/paranoid_datetime.rb +22 -0
  19. data/lib/dm-types/regexp.rb +8 -8
  20. data/lib/dm-types/slug.rb +7 -12
  21. data/lib/dm-types/uri.rb +21 -9
  22. data/lib/dm-types/uuid.rb +18 -11
  23. data/lib/dm-types/yaml.rb +12 -10
  24. data/spec/fixtures/article.rb +0 -2
  25. data/spec/fixtures/bookmark.rb +0 -2
  26. data/spec/fixtures/network_node.rb +0 -2
  27. data/spec/fixtures/person.rb +0 -2
  28. data/spec/fixtures/software_package.rb +0 -2
  29. data/spec/fixtures/ticket.rb +2 -4
  30. data/spec/fixtures/tshirt.rb +3 -5
  31. data/spec/integration/bcrypt_hash_spec.rb +33 -31
  32. data/spec/integration/comma_separated_list_spec.rb +55 -53
  33. data/spec/integration/enum_spec.rb +55 -53
  34. data/spec/integration/file_path_spec.rb +105 -103
  35. data/spec/integration/flag_spec.rb +42 -40
  36. data/spec/integration/ip_address_spec.rb +91 -89
  37. data/spec/integration/json_spec.rb +41 -39
  38. data/spec/integration/slug_spec.rb +36 -34
  39. data/spec/integration/uri_spec.rb +82 -79
  40. data/spec/integration/uuid_spec.rb +63 -61
  41. data/spec/integration/yaml_spec.rb +37 -35
  42. data/spec/spec_helper.rb +7 -36
  43. data/spec/unit/bcrypt_hash_spec.rb +18 -10
  44. data/spec/unit/csv_spec.rb +92 -80
  45. data/spec/unit/enum_spec.rb +27 -42
  46. data/spec/unit/epoch_time_spec.rb +18 -7
  47. data/spec/unit/file_path_spec.rb +15 -10
  48. data/spec/unit/flag_spec.rb +13 -36
  49. data/spec/unit/ip_address_spec.rb +13 -10
  50. data/spec/unit/json_spec.rb +21 -14
  51. data/spec/unit/paranoid_boolean_spec.rb +138 -0
  52. data/spec/unit/paranoid_datetime_spec.rb +143 -0
  53. data/spec/unit/regexp_spec.rb +15 -5
  54. data/spec/unit/uri_spec.rb +13 -9
  55. data/spec/unit/yaml_spec.rb +16 -9
  56. data/tasks/local_gemfile.rake +18 -0
  57. data/tasks/spec.rake +0 -3
  58. metadata +122 -52
@@ -0,0 +1,36 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## Rubinius
17
+ *.rbc
18
+
19
+ ## PROJECT::GENERAL
20
+ *.gem
21
+ coverage
22
+ rdoc
23
+ pkg
24
+ tmp
25
+ doc
26
+ log
27
+ .yardoc
28
+ measurements
29
+
30
+ ## BUNDLER
31
+ .bundle
32
+ Gemfile.local
33
+ Gemfile.lock
34
+
35
+ ## PROJECT::SPECIFIC
36
+ spec/db/
data/Gemfile ADDED
@@ -0,0 +1,147 @@
1
+ # If you're working on more than one datamapper gem at a time, then it's
2
+ # recommended to create a local Gemfile and use this instead of the git
3
+ # sources. This will make sure that you are developing against your
4
+ # other local datamapper sources that you currently work on. Gemfile.local
5
+ # will behave identically to the standard Gemfile apart from the fact that
6
+ # it fetches the datamapper gems from local paths. This means that you can use
7
+ # the same environment variables, like ADAPTER(S) or PLUGIN(S) when running
8
+ # bundle commands. Gemfile.local is added to .gitignore, so you don't need to
9
+ # worry about accidentally checking local development paths into git.
10
+ # In order to create a local Gemfile, all you need to do is run:
11
+ #
12
+ # bundle exec rake local_gemfile
13
+ #
14
+ # This will give you a Gemfile.local file that points to your local clones of
15
+ # the various datamapper gems. It's assumed that all datamapper repo clones
16
+ # reside in the same directory. You can use the Gemfile.local like so for
17
+ # running any bundle command:
18
+ #
19
+ # BUNDLE_GEMFILE=Gemfile.local bundle foo
20
+ #
21
+ # You can also specify which adapter(s) should be part of the bundle by setting
22
+ # an environment variable. This of course also works when using the Gemfile.local
23
+ #
24
+ # bundle foo # dm-sqlite-adapter
25
+ # ADAPTER=mysql bundle foo # dm-mysql-adapter
26
+ # ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter and dm-mysql-adapter
27
+ #
28
+ # Of course you can also use the ADAPTER(S) variable when using the Gemfile.local
29
+ # and running specs against selected adapters.
30
+ #
31
+ # For easily working with adapters supported on your machine, it's recommended
32
+ # that you first install all adapters that you are planning to use or work on
33
+ # by doing something like
34
+ #
35
+ # ADAPTERS=sqlite,mysql,postgres bundle install
36
+ #
37
+ # This will clone the various repositories and make them available to bundler.
38
+ # Once you have them installed you can easily switch between adapters for the
39
+ # various development tasks. Running something like
40
+ #
41
+ # ADAPTER=mysql bundle exec rake spec
42
+ #
43
+ # will make sure that the dm-mysql-adapter is part of the bundle, and will be used
44
+ # when running the specs.
45
+ #
46
+ # You can also specify which plugin(s) should be part of the bundle by setting
47
+ # an environment variable. This also works when using the Gemfile.local
48
+ #
49
+ # bundle foo # dm-migrations
50
+ # PLUGINS=dm-validations bundle foo # dm-migrations and dm-validations
51
+ # PLUGINS=dm-validations,dm-types bundle foo # dm-migrations, dm-validations and dm-types
52
+ #
53
+ # Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run specs
54
+ # for certain adapter/plugin combinations.
55
+ #
56
+ # Finally, to speed up running specs and other tasks, it's recommended to run
57
+ #
58
+ # bundle lock
59
+ #
60
+ # after running 'bundle install' for the first time. This will make 'bundle exec' run
61
+ # a lot faster compared to the unlocked version. With an unlocked bundle you would
62
+ # typically just run 'bundle install' from time to time to fetch the latest sources from
63
+ # upstream. When you locked your bundle, you need to run
64
+ #
65
+ # bundle install --relock
66
+ #
67
+ # to make sure to fetch the latest updates and then lock the bundle again. Gemfile.lock
68
+ # is added to the .gitignore file, so you don't need to worry about accidentally checking
69
+ # it into version control.
70
+
71
+ source 'http://rubygems.org'
72
+
73
+ DATAMAPPER = 'git://github.com/datamapper'
74
+ DM_VERSION = '~> 1.0.0.rc1'
75
+
76
+ group :runtime do # Runtime dependencies (as in the gemspec)
77
+
78
+ if ENV['EXTLIB']
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
+ else
81
+ gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
82
+ end
83
+
84
+ gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
85
+ gem 'fastercsv', '~> 1.5.0'
86
+ gem 'json_pure', '~> 1.4.3'
87
+ gem 'uuidtools', '~> 2.1.1'
88
+ gem 'stringex', '~> 1.1.0'
89
+
90
+ end
91
+
92
+ group(:development) do # Development dependencies (as in the gemspec)
93
+
94
+ gem 'dm-validations', DM_VERSION, :git => "#{DATAMAPPER}/dm-validations.git"
95
+
96
+ gem 'rake', '~> 0.8.7'
97
+ gem 'rspec', '~> 1.3'
98
+ gem 'jeweler', '~> 1.4'
99
+
100
+ end
101
+
102
+ group :quality do # These gems contain rake tasks that check the quality of the source code
103
+
104
+ gem 'metric_fu', '~> 1.3'
105
+ gem 'rcov', '~> 0.9.7'
106
+ gem 'reek', '~> 1.2.7'
107
+ gem 'roodi', '~> 2.1'
108
+ gem 'yard', '~> 0.5'
109
+ gem 'yardstick', '~> 0.1'
110
+
111
+ end
112
+
113
+ group :datamapper do # We need this because we want to pin these dependencies to their git master sources
114
+
115
+ adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
116
+ adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
117
+
118
+ unless adapters.empty?
119
+
120
+ DO_VERSION = '~> 0.10.2'
121
+ DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
122
+
123
+ gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
124
+
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
130
+ end
131
+
132
+ gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
133
+
134
+ adapters.each do |adapter|
135
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
136
+ end
137
+
138
+ end
139
+
140
+ plugins = ENV['PLUGINS'] || ENV['PLUGIN']
141
+ plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
142
+
143
+ plugins.each do |plugin|
144
+ gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
145
+ end
146
+
147
+ end
data/Rakefile CHANGED
@@ -15,15 +15,14 @@ begin
15
15
 
16
16
  gem.rubyforge_project = 'datamapper'
17
17
 
18
- gem.add_dependency 'bcrypt-ruby', '~> 2.1.2'
19
- gem.add_dependency 'dm-core', '~> 0.10.2'
20
- gem.add_dependency 'fastercsv', '~> 1.5.0'
21
- gem.add_dependency 'json_pure', '~> 1.2.0'
22
- gem.add_dependency 'uuidtools', '~> 2.1.1'
23
- gem.add_dependency 'stringex', '~> 1.1.0'
18
+ gem.add_dependency 'dm-core', '~> 1.0.0.rc1'
19
+ gem.add_dependency 'fastercsv', '~> 1.5.0'
20
+ gem.add_dependency 'json_pure', '~> 1.4.3'
21
+ gem.add_dependency 'uuidtools', '~> 2.1.1'
22
+ gem.add_dependency 'stringex', '~> 1.1.0'
24
23
 
25
- gem.add_development_dependency 'rspec', '~> 1.2.9'
26
- gem.add_development_dependency 'yard', '~> 0.4.0'
24
+ gem.add_development_dependency 'rspec', '~> 1.3'
25
+ gem.add_development_dependency 'dm-validations', '~> 1.0.0.rc1'
27
26
  end
28
27
 
29
28
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 1.0.0.rc1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-types}
8
- s.version = "0.10.2"
8
+ s.version = "1.0.0.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
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{2009-12-11}
12
+ s.date = %q{2010-05-19}
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 = [
@@ -17,7 +17,9 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
- "LICENSE",
20
+ ".gitignore",
21
+ "Gemfile",
22
+ "LICENSE",
21
23
  "README.rdoc",
22
24
  "Rakefile",
23
25
  "VERSION",
@@ -32,6 +34,9 @@ Gem::Specification.new do |s|
32
34
  "lib/dm-types/flag.rb",
33
35
  "lib/dm-types/ip_address.rb",
34
36
  "lib/dm-types/json.rb",
37
+ "lib/dm-types/paranoid/base.rb",
38
+ "lib/dm-types/paranoid_boolean.rb",
39
+ "lib/dm-types/paranoid_datetime.rb",
35
40
  "lib/dm-types/regexp.rb",
36
41
  "lib/dm-types/slug.rb",
37
42
  "lib/dm-types/uri.rb",
@@ -68,10 +73,13 @@ Gem::Specification.new do |s|
68
73
  "spec/unit/flag_spec.rb",
69
74
  "spec/unit/ip_address_spec.rb",
70
75
  "spec/unit/json_spec.rb",
76
+ "spec/unit/paranoid_boolean_spec.rb",
77
+ "spec/unit/paranoid_datetime_spec.rb",
71
78
  "spec/unit/regexp_spec.rb",
72
79
  "spec/unit/uri_spec.rb",
73
80
  "spec/unit/yaml_spec.rb",
74
81
  "tasks/ci.rake",
82
+ "tasks/local_gemfile.rake",
75
83
  "tasks/metrics.rake",
76
84
  "tasks/spec.rake",
77
85
  "tasks/yard.rake",
@@ -81,41 +89,74 @@ Gem::Specification.new do |s|
81
89
  s.rdoc_options = ["--charset=UTF-8"]
82
90
  s.require_paths = ["lib"]
83
91
  s.rubyforge_project = %q{datamapper}
84
- s.rubygems_version = %q{1.3.5}
92
+ s.rubygems_version = %q{1.3.6}
85
93
  s.summary = %q{DataMapper plugin providing extra data types}
94
+ s.test_files = [
95
+ "spec/fixtures/article.rb",
96
+ "spec/fixtures/bookmark.rb",
97
+ "spec/fixtures/invention.rb",
98
+ "spec/fixtures/network_node.rb",
99
+ "spec/fixtures/person.rb",
100
+ "spec/fixtures/software_package.rb",
101
+ "spec/fixtures/ticket.rb",
102
+ "spec/fixtures/tshirt.rb",
103
+ "spec/integration/bcrypt_hash_spec.rb",
104
+ "spec/integration/comma_separated_list_spec.rb",
105
+ "spec/integration/enum_spec.rb",
106
+ "spec/integration/file_path_spec.rb",
107
+ "spec/integration/flag_spec.rb",
108
+ "spec/integration/ip_address_spec.rb",
109
+ "spec/integration/json_spec.rb",
110
+ "spec/integration/slug_spec.rb",
111
+ "spec/integration/uri_spec.rb",
112
+ "spec/integration/uuid_spec.rb",
113
+ "spec/integration/yaml_spec.rb",
114
+ "spec/shared/identity_function_group.rb",
115
+ "spec/spec_helper.rb",
116
+ "spec/unit/bcrypt_hash_spec.rb",
117
+ "spec/unit/csv_spec.rb",
118
+ "spec/unit/enum_spec.rb",
119
+ "spec/unit/epoch_time_spec.rb",
120
+ "spec/unit/file_path_spec.rb",
121
+ "spec/unit/flag_spec.rb",
122
+ "spec/unit/ip_address_spec.rb",
123
+ "spec/unit/json_spec.rb",
124
+ "spec/unit/paranoid_boolean_spec.rb",
125
+ "spec/unit/paranoid_datetime_spec.rb",
126
+ "spec/unit/regexp_spec.rb",
127
+ "spec/unit/uri_spec.rb",
128
+ "spec/unit/yaml_spec.rb"
129
+ ]
86
130
 
87
131
  if s.respond_to? :specification_version then
88
132
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
89
133
  s.specification_version = 3
90
134
 
91
135
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
92
- s.add_runtime_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
93
- s.add_runtime_dependency(%q<dm-core>, ["~> 0.10.2"])
136
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
94
137
  s.add_runtime_dependency(%q<fastercsv>, ["~> 1.5.0"])
95
- s.add_runtime_dependency(%q<json_pure>, ["~> 1.2.0"])
138
+ s.add_runtime_dependency(%q<json_pure>, ["~> 1.4.3"])
96
139
  s.add_runtime_dependency(%q<uuidtools>, ["~> 2.1.1"])
97
140
  s.add_runtime_dependency(%q<stringex>, ["~> 1.1.0"])
98
- s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
99
- s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
141
+ s.add_development_dependency(%q<rspec>, ["~> 1.3"])
142
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
100
143
  else
101
- s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
102
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
144
+ s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
103
145
  s.add_dependency(%q<fastercsv>, ["~> 1.5.0"])
104
- s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
146
+ s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
105
147
  s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
106
148
  s.add_dependency(%q<stringex>, ["~> 1.1.0"])
107
- s.add_dependency(%q<rspec>, ["~> 1.2.9"])
108
- s.add_dependency(%q<yard>, ["~> 0.4.0"])
149
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
150
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
109
151
  end
110
152
  else
111
- s.add_dependency(%q<bcrypt-ruby>, ["~> 2.1.2"])
112
- s.add_dependency(%q<dm-core>, ["~> 0.10.2"])
153
+ s.add_dependency(%q<dm-core>, ["~> 1.0.0.rc1"])
113
154
  s.add_dependency(%q<fastercsv>, ["~> 1.5.0"])
114
- s.add_dependency(%q<json_pure>, ["~> 1.2.0"])
155
+ s.add_dependency(%q<json_pure>, ["~> 1.4.3"])
115
156
  s.add_dependency(%q<uuidtools>, ["~> 2.1.1"])
116
157
  s.add_dependency(%q<stringex>, ["~> 1.1.0"])
117
- s.add_dependency(%q<rspec>, ["~> 1.2.9"])
118
- s.add_dependency(%q<yard>, ["~> 0.4.0"])
158
+ s.add_dependency(%q<rspec>, ["~> 1.3"])
159
+ s.add_dependency(%q<dm-validations>, ["~> 1.0.0.rc1"])
119
160
  end
120
161
  end
121
162
 
@@ -1,23 +1,28 @@
1
- require 'pathname'
1
+ require 'dm-core'
2
2
 
3
- module DataMapper
4
- module Types
5
- dir = (Pathname(__FILE__).dirname.expand_path / 'dm-types').to_s
3
+ begin
4
+ require 'active_support/core_ext/date_time/conversions'
5
+ rescue LoadError
6
+ require 'extlib/datetime'
7
+ end
6
8
 
7
- autoload :BCryptHash, dir / 'bcrypt_hash'
8
- autoload :CommaSeparatedList, dir / 'comma_separated_list'
9
- autoload :Csv, dir / 'csv'
10
- autoload :Enum, dir / 'enum'
11
- autoload :EpochTime, dir / 'epoch_time'
12
- autoload :FilePath, dir / 'file_path'
13
- autoload :Flag, dir / 'flag'
14
- autoload :IPAddress, dir / 'ip_address'
15
- autoload :Json, dir / 'json'
16
- autoload :Regexp, dir / 'regexp'
17
- autoload :Serial, dir / 'serial'
18
- autoload :Slug, dir / 'slug'
19
- autoload :URI, dir / 'uri'
20
- autoload :UUID, dir / 'uuid'
21
- autoload :Yaml, dir / 'yaml'
9
+ module DataMapper
10
+ class Property
11
+ autoload :CommaSeparatedList, 'dm-types/comma_separated_list'
12
+ autoload :Csv, 'dm-types/csv'
13
+ autoload :BCryptHash, 'dm-types/bcrypt_hash'
14
+ autoload :Enum, 'dm-types/enum'
15
+ autoload :EpochTime, 'dm-types/epoch_time'
16
+ autoload :FilePath, 'dm-types/file_path'
17
+ autoload :Flag, 'dm-types/flag'
18
+ autoload :IPAddress, 'dm-types/ip_address'
19
+ autoload :Json, 'dm-types/json'
20
+ autoload :Regexp, 'dm-types/regexp'
21
+ autoload :ParanoidBoolean, 'dm-types/paranoid_boolean'
22
+ autoload :ParanoidDateTime, 'dm-types/paranoid_datetime'
23
+ autoload :Slug, 'dm-types/slug'
24
+ autoload :UUID, 'dm-types/uuid'
25
+ autoload :URI, 'dm-types/uri'
26
+ autoload :Yaml, 'dm-types/yaml'
22
27
  end
23
28
  end
@@ -1,30 +1,34 @@
1
+ require 'dm-core'
1
2
  require 'bcrypt'
2
3
 
3
4
  module DataMapper
4
- module Types
5
- class BCryptHash < DataMapper::Type
6
- primitive String
7
- length 60
5
+ class Property
6
+ class BCryptHash < String
7
+ length 60
8
8
 
9
- def self.load(value, property)
10
- typecast(value, property)
9
+ def primitive?(value)
10
+ value.kind_of?(BCrypt::Password)
11
11
  end
12
12
 
13
- def self.dump(value, property)
14
- typecast(value, property)
15
- end
16
-
17
- def self.typecast(value, property)
13
+ def load(value)
18
14
  if value.nil?
19
15
  nil
20
16
  else
21
17
  begin
22
- value.is_a?(BCrypt::Password) ? value : BCrypt::Password.new(value)
18
+ primitive?(value) ? value : BCrypt::Password.new(value)
23
19
  rescue BCrypt::Errors::InvalidHash
24
20
  BCrypt::Password.create(value, :cost => BCrypt::Engine::DEFAULT_COST)
25
21
  end
26
22
  end
27
23
  end
24
+
25
+ def dump(value)
26
+ load(value)
27
+ end
28
+
29
+ def typecast_to_primitive(value)
30
+ load(value)
31
+ end
28
32
  end # class BCryptHash
29
- end # module Types
33
+ end # class Property
30
34
  end # module DataMapper
@@ -1,31 +1,26 @@
1
- module DataMapper
2
- module Types
1
+ require 'dm-core'
2
+ require 'dm-types/yaml'
3
3
 
4
+ module DataMapper
5
+ class Property
4
6
  class CommaSeparatedList < Yaml
5
- # this must be set even though Yaml already
6
- # uses String primitive
7
- #
8
- # current DM::Type behavior probably needs to
9
- # be improved for cases like this
10
- primitive String
11
-
12
- def self.dump(value, property)
7
+ def dump(value)
13
8
  if value.nil?
14
9
  nil
15
- elsif value.kind_of?(Array)
16
- super(value, property)
17
- elsif value.kind_of?(String)
10
+ elsif value.kind_of?(::Array)
11
+ super(value)
12
+ elsif value.kind_of?(::String)
18
13
  v = (value || "").split(",").
19
14
  compact.
20
15
  map { |i| i.downcase.strip }.
21
16
  reject { |i| i.blank? }.
22
17
  uniq
23
- super(v, property)
18
+ super(v)
24
19
  else
25
20
  raise ArgumentError, "+value+ of CommaSeparatedList must be a string, an array or nil, but given #{value.inspect}"
26
21
  end
27
- end # self.dump
22
+ end # dump
28
23
  end # CommaSeparatedList
29
24
 
30
- end # Types
25
+ end # Property
31
26
  end # DataMapper