dm-types 0.9.11 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/{History.txt → History.rdoc} +5 -4
  2. data/LICENSE +16 -14
  3. data/Manifest.txt +13 -3
  4. data/{README.txt → README.rdoc} +0 -0
  5. data/Rakefile +3 -4
  6. data/TODO +74 -0
  7. data/lib/dm-types.rb +15 -18
  8. data/lib/dm-types/bcrypt_hash.rb +1 -4
  9. data/lib/dm-types/comma_separated_list.rb +31 -0
  10. data/lib/dm-types/csv.rb +12 -18
  11. data/lib/dm-types/enum.rb +18 -15
  12. data/lib/dm-types/epoch_time.rb +6 -11
  13. data/lib/dm-types/file_path.rb +5 -4
  14. data/lib/dm-types/flag.rb +14 -13
  15. data/lib/dm-types/ip_address.rb +1 -0
  16. data/lib/dm-types/json.rb +5 -11
  17. data/lib/dm-types/regexp.rb +2 -3
  18. data/lib/dm-types/slug.rb +8 -17
  19. data/lib/dm-types/uri.rb +8 -14
  20. data/lib/dm-types/uuid.rb +9 -15
  21. data/lib/dm-types/version.rb +1 -1
  22. data/lib/dm-types/yaml.rb +4 -3
  23. data/spec/fixtures/article.rb +39 -0
  24. data/spec/fixtures/bookmark.rb +27 -0
  25. data/spec/fixtures/invention.rb +9 -0
  26. data/spec/fixtures/network_node.rb +40 -0
  27. data/spec/fixtures/person.rb +29 -0
  28. data/spec/fixtures/software_package.rb +37 -0
  29. data/spec/fixtures/ticket.rb +25 -0
  30. data/spec/fixtures/tshirt.rb +28 -0
  31. data/spec/integration/bcrypt_hash_spec.rb +37 -55
  32. data/spec/integration/comma_separated_list_spec.rb +89 -0
  33. data/spec/integration/enum_spec.rb +62 -42
  34. data/spec/integration/file_path_spec.rb +149 -17
  35. data/spec/integration/flag_spec.rb +56 -25
  36. data/spec/integration/ip_address_spec.rb +142 -17
  37. data/spec/integration/json_spec.rb +60 -17
  38. data/spec/integration/slug_spec.rb +39 -40
  39. data/spec/integration/uri_spec.rb +126 -21
  40. data/spec/integration/uuid_spec.rb +84 -30
  41. data/spec/integration/yaml_spec.rb +55 -25
  42. data/spec/shared/identity_function_group.rb +5 -0
  43. data/spec/spec.opts +1 -0
  44. data/spec/spec_helper.rb +49 -17
  45. data/spec/unit/bcrypt_hash_spec.rb +107 -64
  46. data/spec/unit/csv_spec.rb +111 -27
  47. data/spec/unit/enum_spec.rb +128 -87
  48. data/spec/unit/epoch_time_spec.rb +57 -32
  49. data/spec/unit/file_path_spec.rb +55 -34
  50. data/spec/unit/flag_spec.rb +102 -65
  51. data/spec/unit/ip_address_spec.rb +90 -40
  52. data/spec/unit/json_spec.rb +108 -41
  53. data/spec/unit/regexp_spec.rb +47 -17
  54. data/spec/unit/uri_spec.rb +57 -46
  55. data/spec/unit/yaml_spec.rb +91 -45
  56. data/tasks/install.rb +1 -1
  57. data/tasks/spec.rb +4 -4
  58. metadata +25 -32
  59. data/lib/dm-types/serial.rb +0 -8
@@ -1,9 +1,10 @@
1
- === 0.9.11 / 2009-03-29
1
+ === 0.10.0 / 2009-10-15
2
2
 
3
- * 2 bug fixes:
3
+ * Updated to work with dm-core 0.10.0
4
+
5
+ === 0.9.11 / 2009-03-29
4
6
 
5
- * Remove dependency on bcrypt
6
- * Remove dependency on json
7
+ * No changes this version
7
8
 
8
9
  === 0.9.10 / 2009-01-19
9
10
 
data/LICENSE CHANGED
@@ -1,20 +1,22 @@
1
- Copyright (c) 2007 Sam Smoot
1
+ Copyright (c) 2007, 2008, 2009 Sam Smoot, Dan Kubb
2
2
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
10
11
 
11
12
  The above copyright notice and this permission notice shall be
12
13
  included in all copies or substantial portions of the Software.
13
14
 
14
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt CHANGED
@@ -1,11 +1,12 @@
1
- History.txt
1
+ History.rdoc
2
2
  LICENSE
3
3
  Manifest.txt
4
- README.txt
4
+ README.rdoc
5
5
  Rakefile
6
6
  TODO
7
7
  lib/dm-types.rb
8
8
  lib/dm-types/bcrypt_hash.rb
9
+ lib/dm-types/comma_separated_list.rb
9
10
  lib/dm-types/csv.rb
10
11
  lib/dm-types/enum.rb
11
12
  lib/dm-types/epoch_time.rb
@@ -14,13 +15,21 @@ lib/dm-types/flag.rb
14
15
  lib/dm-types/ip_address.rb
15
16
  lib/dm-types/json.rb
16
17
  lib/dm-types/regexp.rb
17
- lib/dm-types/serial.rb
18
18
  lib/dm-types/slug.rb
19
19
  lib/dm-types/uri.rb
20
20
  lib/dm-types/uuid.rb
21
21
  lib/dm-types/version.rb
22
22
  lib/dm-types/yaml.rb
23
+ spec/fixtures/article.rb
24
+ spec/fixtures/bookmark.rb
25
+ spec/fixtures/invention.rb
26
+ spec/fixtures/network_node.rb
27
+ spec/fixtures/person.rb
28
+ spec/fixtures/software_package.rb
29
+ spec/fixtures/ticket.rb
30
+ spec/fixtures/tshirt.rb
23
31
  spec/integration/bcrypt_hash_spec.rb
32
+ spec/integration/comma_separated_list_spec.rb
24
33
  spec/integration/enum_spec.rb
25
34
  spec/integration/file_path_spec.rb
26
35
  spec/integration/flag_spec.rb
@@ -30,6 +39,7 @@ spec/integration/slug_spec.rb
30
39
  spec/integration/uri_spec.rb
31
40
  spec/integration/uuid_spec.rb
32
41
  spec/integration/yaml_spec.rb
42
+ spec/shared/identity_function_group.rb
33
43
  spec/spec.opts
34
44
  spec/spec_helper.rb
35
45
  spec/unit/bcrypt_hash_spec.rb
File without changes
data/Rakefile CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'pathname'
2
- require 'rubygems'
3
2
 
4
3
  ROOT = Pathname(__FILE__).dirname.expand_path
5
4
  JRUBY = RUBY_PLATFORM =~ /java/
@@ -12,12 +11,12 @@ AUTHOR = 'Sam Smoot'
12
11
  EMAIL = 'ssmoot [a] gmail [d] com'
13
12
  GEM_NAME = 'dm-types'
14
13
  GEM_VERSION = DataMapper::Types::VERSION
15
- GEM_DEPENDENCIES = [['dm-core', GEM_VERSION], ['addressable', '~>2.0.2']]
14
+ GEM_DEPENDENCIES = [['dm-core', GEM_VERSION]]
16
15
  GEM_CLEAN = %w[ log pkg coverage ]
17
- GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }
16
+ GEM_EXTRAS = { :has_rdoc => true, :extra_rdoc_files => %w[ README.rdoc LICENSE TODO History.rdoc ] }
18
17
 
19
18
  PROJECT_NAME = 'datamapper'
20
- PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
19
+ PROJECT_URL = "http://github.com/datamapper/dm-more/tree/master/#{GEM_NAME}"
21
20
  PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'DataMapper plugin providing extra data types'
22
21
 
23
22
  [ ROOT, ROOT.parent ].each do |dir|
data/TODO CHANGED
@@ -0,0 +1,74 @@
1
+ ### -*- mode:org -*-
2
+
3
+ * Spec suite improvement
4
+ ** integration
5
+ *** DONE bcrypt_hash_spec.rb
6
+ *** DONE enum_spec.rb
7
+ *** DONE file_path_spec.rb
8
+ *** DONE flag_spec.rb
9
+ *** DONE ip_address_spec.rb
10
+ *** DONE json_spec.rb
11
+ *** DONE slug_spec.rb
12
+ *** DONE uri_spec.rb
13
+ *** DONE uuid_spec.rb
14
+ *** DONE yaml_spec.rb
15
+
16
+ MK reworked spec suite to the point we actually
17
+ can trust it
18
+
19
+ ** fixtures
20
+
21
+ It should be perfectly possible to combine fixture
22
+ models from dm-validations and dm-types, and publish
23
+ a little gem that all DM plugins developers can use
24
+ as a basis
25
+
26
+ *** TODO Investigate if sharing of models across DM plugins makes sense
27
+
28
+ * Ideas/prototypes of New types
29
+ ** SHA1 hash
30
+
31
+ Case: when you want to compute SHA1 of another property
32
+ and store it. Useful for file stores, caching and other things.
33
+
34
+ Would be a good example of how types can interact with models
35
+ via property binding
36
+
37
+ ** LowercaseString
38
+
39
+ A string type subclass that downcases the input
40
+
41
+ Case: CASES WHERE YOU WOULD HATE TO SEE UPPERCASE!
42
+
43
+ ** EmbeddedValue
44
+
45
+ An experiment of type/model interaction: takes a class
46
+ and uses YAML/JSON for serialization
47
+
48
+ To complete the picture we would need to add validation
49
+ delegation (so embedded object can add errors to
50
+ the parent if it makes sense), but it would be helpful
51
+ to shape up Property/Type refactoring, and should take
52
+ as little time as one evening
53
+
54
+ ** ZIP
55
+
56
+ Input: a string, output: a ZIP object that is smart enough
57
+ to provide predicates
58
+
59
+ Need to find a library for zips that would fit
60
+
61
+ ** Address
62
+
63
+ Same as ZIP but for actuall address. Again, stored
64
+ in YAML I suppose
65
+
66
+ ** Coordinate
67
+
68
+ Input: two floats or two strings can be cast to floats,
69
+ output: object that knows how to render a map for itself
70
+
71
+ ** DNA
72
+
73
+ Mostly for fun, to see how far we can push current types API
74
+ with little help from BioRuby
data/lib/dm-types.rb CHANGED
@@ -1,26 +1,23 @@
1
1
  require 'pathname'
2
- require 'rubygems'
3
-
4
- gem 'dm-core', '0.9.11'
5
- require 'dm-core'
6
2
 
7
3
  module DataMapper
8
4
  module Types
9
5
  dir = (Pathname(__FILE__).dirname.expand_path / 'dm-types').to_s
10
6
 
11
- autoload :BCryptHash, dir / 'bcrypt_hash'
12
- autoload :Csv, dir / 'csv'
13
- autoload :Enum, dir / 'enum'
14
- autoload :EpochTime, dir / 'epoch_time'
15
- autoload :FilePath, dir / 'file_path'
16
- autoload :Flag, dir / 'flag'
17
- autoload :IPAddress, dir / 'ip_address'
18
- autoload :Json, dir / 'json'
19
- autoload :Regexp, dir / 'regexp'
20
- autoload :Serial, dir / 'serial'
21
- autoload :Slug, dir / 'slug'
22
- autoload :URI, dir / 'uri'
23
- autoload :UUID, dir / 'uuid'
24
- autoload :Yaml, dir / 'yaml'
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'
25
22
  end
26
23
  end
@@ -1,13 +1,10 @@
1
- require 'rubygems'
2
-
3
- gem 'bcrypt-ruby', '~>2.0.5'
4
1
  require 'bcrypt'
5
2
 
6
3
  module DataMapper
7
4
  module Types
8
5
  class BCryptHash < DataMapper::Type
9
6
  primitive String
10
- size 60
7
+ length 60
11
8
 
12
9
  def self.load(value, property)
13
10
  typecast(value, property)
@@ -0,0 +1,31 @@
1
+ module DataMapper
2
+ module Types
3
+
4
+ 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)
13
+ if value.nil?
14
+ nil
15
+ elsif value.kind_of?(Array)
16
+ super(value, property)
17
+ elsif value.kind_of?(String)
18
+ v = (value || "").split(",").
19
+ compact.
20
+ map { |i| i.downcase.strip }.
21
+ reject { |i| i.blank? }.
22
+ uniq
23
+ super(v, property)
24
+ else
25
+ raise ArgumentError, "+value+ of CommaSeparatedList must be a string, an array or nil, but given #{value.inspect}"
26
+ end
27
+ end # self.dump
28
+ end # CommaSeparatedList
29
+
30
+ end # Types
31
+ end # DataMapper
data/lib/dm-types/csv.rb CHANGED
@@ -1,37 +1,31 @@
1
1
  if RUBY_VERSION >= '1.9.0'
2
- require 'csv'
2
+ require 'csv'
3
3
  else
4
- begin
5
- gem 'fastercsv', '~>1.4.0'
6
- require 'fastercsv'
7
- CSV = FasterCSV
8
- rescue LoadError
9
- nil
10
- end
4
+ require 'fastercsv' # must be ~>1.5
5
+ CSV = FasterCSV unless defined?(CSV)
11
6
  end
12
7
 
13
8
  module DataMapper
14
9
  module Types
15
10
  class Csv < DataMapper::Type
16
11
  primitive Text
17
- lazy true
12
+ lazy true
18
13
 
19
14
  def self.load(value, property)
20
15
  case value
21
- when String then CSV.parse(value)
22
- when Array then value
23
- else nil
16
+ when String then CSV.parse(value)
17
+ when Array then value
18
+ else
19
+ nil
24
20
  end
25
21
  end
26
22
 
27
23
  def self.dump(value, property)
28
24
  case value
29
- when Array then
30
- CSV.generate do |csv|
31
- value.each { |row| csv << row }
32
- end
33
- when String then value
34
- else nil
25
+ when Array then CSV.generate { |csv| value.each { |row| csv << row } }
26
+ when String then value
27
+ else
28
+ nil
35
29
  end
36
30
  end
37
31
  end # class Csv
data/lib/dm-types/enum.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module DataMapper
2
2
  module Types
3
- class Enum < DataMapper::Type(Integer)
3
+ class Enum < Type
4
+ primitive Integer
5
+
4
6
  def self.inherited(target)
5
7
  target.instance_variable_set("@primitive", self.primitive)
6
8
  end
@@ -49,22 +51,23 @@ module DataMapper
49
51
  else value
50
52
  end
51
53
  end
52
- end # class Enum
53
- end # module Types
54
54
 
55
- if defined?(Validate)
56
- module Validate
57
- module AutoValidate
58
- alias :orig_auto_generate_validations :auto_generate_validations
59
- def auto_generate_validations(property)
60
- orig_auto_generate_validations(property)
61
- return unless property.options[:auto_validation]
55
+ def self.bind(property)
56
+ if defined?(::DataMapper::Validate)
57
+ model = property.model
62
58
 
63
- if property.type.ancestors.include?(Types::Enum)
64
- validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within)
59
+ unless model.skip_auto_validation_for?(property)
60
+ if property.type.ancestors.include?(Types::Enum)
61
+ model.class_eval do
62
+ flag_map = property.type.flag_map
63
+ allowed = flag_map.values_at(*flag_map.keys.sort)
64
+
65
+ validates_within property.name, options_with_message({ :set => allowed }, property, :within)
66
+ end
67
+ end
65
68
  end
66
69
  end
67
70
  end
68
- end
69
- end
70
- end # module DataMapper
71
+ end # class Enum
72
+ end # module Types
73
+ end # module DataMapper
@@ -4,8 +4,7 @@ module DataMapper
4
4
  primitive Integer
5
5
 
6
6
  def self.load(value, property)
7
- case value
8
- when Integer
7
+ if value.kind_of?(Integer)
9
8
  Time.at(value)
10
9
  else
11
10
  value
@@ -14,14 +13,10 @@ module DataMapper
14
13
 
15
14
  def self.dump(value, property)
16
15
  case value
17
- when Integer
18
- value
19
- when Time
20
- value.to_i
21
- when DateTime
22
- Time.parse(value.to_s).to_i
16
+ when Integer, Time then value.to_i
17
+ when DateTime then value.to_time.to_i
23
18
  end
24
19
  end
25
- end # class EpochTime
26
- end # module Types
27
- end # module DataMapper
20
+ end # class EpochTime
21
+ end # module Types
22
+ end # module DataMapper
@@ -4,9 +4,10 @@ module DataMapper
4
4
  module Types
5
5
  class FilePath < DataMapper::Type
6
6
  primitive String
7
+ length 255
7
8
 
8
9
  def self.load(value, property)
9
- if value.nil?
10
+ if value.blank?
10
11
  nil
11
12
  else
12
13
  Pathname.new(value)
@@ -14,7 +15,7 @@ module DataMapper
14
15
  end
15
16
 
16
17
  def self.dump(value, property)
17
- return nil if value.nil?
18
+ return nil if value.blank?
18
19
  value.to_s
19
20
  end
20
21
 
@@ -23,5 +24,5 @@ module DataMapper
23
24
  value.kind_of?(Pathname) ? value : load(value, property)
24
25
  end
25
26
  end # class FilePath
26
- end # module Types
27
- end # module DataMapper
27
+ end # module Types
28
+ end # module DataMapper