dm-types 1.0.0 → 1.0.1

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 (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
@@ -1,9 +1,7 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
4
3
 
5
- Invention = Struct.new(:name)
4
+ Invention = Struct.new(:name)
6
5
 
7
- end
8
6
  end
9
7
  end
@@ -1,38 +1,36 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
4
-
5
- class NetworkNode
6
- #
7
- # Behaviors
8
- #
9
-
10
- include ::DataMapper::Resource
11
-
12
- #
13
- # Properties
14
- #
15
-
16
- property :id, Serial
17
- property :ip_address, IPAddress
18
- property :cidr_subnet_bits, Integer
19
- property :node_uuid, UUID
20
-
21
- #
22
- # API
23
- #
24
-
25
- alias uuid node_uuid
26
- alias uuid= node_uuid=
27
-
28
- def runs_ipv6?
29
- self.ip_address.ipv6?
30
- end
31
-
32
- def runs_ipv4?
33
- self.ip_address.ipv4?
34
- end
35
- end # NetworkNode
36
- end # Fixtures
37
- end # Types
2
+ module TypesFixtures
3
+
4
+ class NetworkNode
5
+ #
6
+ # Behaviors
7
+ #
8
+
9
+ include ::DataMapper::Resource
10
+
11
+ #
12
+ # Properties
13
+ #
14
+
15
+ property :id, Serial
16
+ property :ip_address, IPAddress
17
+ property :cidr_subnet_bits, Integer
18
+ property :node_uuid, UUID
19
+
20
+ #
21
+ # API
22
+ #
23
+
24
+ alias uuid node_uuid
25
+ alias uuid= node_uuid=
26
+
27
+ def runs_ipv6?
28
+ self.ip_address.ipv6?
29
+ end
30
+
31
+ def runs_ipv4?
32
+ self.ip_address.ipv4?
33
+ end
34
+ end # NetworkNode
35
+ end # TypesFixtures
38
36
  end # DataMapper
@@ -1,27 +1,24 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
3
+ class Person
4
+ #
5
+ # Behaviors
6
+ #
4
7
 
5
- class Person
6
- #
7
- # Behaviors
8
- #
8
+ include DataMapper::Resource
9
9
 
10
- include DataMapper::Resource
10
+ #
11
+ # Properties
12
+ #
11
13
 
12
- #
13
- # Properties
14
- #
14
+ property :id, Serial
15
+ property :name, String
16
+ property :positions, Json
17
+ property :inventions, Yaml
15
18
 
16
- property :id, Serial
17
- property :name, String
18
- property :positions, Json
19
- property :inventions, Yaml
19
+ property :interests, CommaSeparatedList
20
20
 
21
- property :interests, CommaSeparatedList
22
-
23
- property :password, BCryptHash
24
- end
21
+ property :password, BCryptHash
25
22
  end
26
23
  end
27
24
  end
@@ -1,35 +1,33 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
4
3
 
5
- class SoftwarePackage
6
- #
7
- # Behaviors
8
- #
4
+ class SoftwarePackage
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
17
- without_auto_validations do
18
- property :node_number, Integer, :index => true
15
+ property :id, Serial
16
+ without_auto_validations do
17
+ property :node_number, Integer, :index => true
19
18
 
20
- property :source_path, FilePath
21
- property :destination_path, FilePath
19
+ property :source_path, FilePath
20
+ property :destination_path, FilePath
22
21
 
23
- property :product, String
24
- property :version, String
25
- property :released_at, DateTime
22
+ property :product, String
23
+ property :version, String
24
+ property :released_at, DateTime
26
25
 
27
- property :security_update, Boolean
26
+ property :security_update, Boolean
28
27
 
29
- property :installed_at, DateTime
30
- property :installed_by, String
31
- end
32
- end # SoftwarePackage
33
- end # Fixtures
34
- end # Types
28
+ property :installed_at, DateTime
29
+ property :installed_by, String
30
+ end
31
+ end # SoftwarePackage
32
+ end # TypesFixtures
35
33
  end # DataMapper
@@ -1,23 +1,21 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
4
- class Ticket
5
- #
6
- # Behaviors
7
- #
2
+ module TypesFixtures
3
+ class Ticket
4
+ #
5
+ # Behaviors
6
+ #
8
7
 
9
- include DataMapper::Resource
10
- include DataMapper::Validations
8
+ include DataMapper::Resource
9
+ include DataMapper::Validations
11
10
 
12
- #
13
- # Properties
14
- #
11
+ #
12
+ # Properties
13
+ #
15
14
 
16
- property :id, Serial
17
- property :title, String, :length => 255
18
- property :body, Text
19
- property :status, Enum[:unconfirmed, :confirmed, :assigned, :resolved, :not_applicable]
20
- end # Ticket
21
- end
15
+ property :id, Serial
16
+ property :title, String, :length => 255
17
+ property :body, Text
18
+ property :status, Enum[:unconfirmed, :confirmed, :assigned, :resolved, :not_applicable]
19
+ end # Ticket
22
20
  end
23
21
  end
@@ -1,6 +1,5 @@
1
1
  module DataMapper
2
- module Types
3
- module Fixtures
2
+ module TypesFixtures
4
3
 
5
4
  class TShirt
6
5
  #
@@ -21,6 +20,5 @@ module DataMapper
21
20
  property :color, Enum[:white, :black, :red, :orange, :yellow, :green, :cyan, :blue, :purple]
22
21
  property :size, Flag[:xs, :small, :medium, :large, :xl, :xxl], :default => :xs
23
22
  end # Shirt
24
- end # Fixtures
25
- end # Types
23
+ end # TypesFixtures
26
24
  end # DataMapper
@@ -4,13 +4,13 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/person'
6
6
 
7
- describe DataMapper::Types::Fixtures::Person do
7
+ describe DataMapper::TypesFixtures::Person do
8
8
  supported_by :all do
9
9
  before :all do
10
- @resource = DataMapper::Types::Fixtures::Person.create(:password => 'DataMapper R0cks!')
11
- DataMapper::Types::Fixtures::Person.create(:password => 'password1')
10
+ @resource = DataMapper::TypesFixtures::Person.create(:password => 'DataMapper R0cks!')
11
+ DataMapper::TypesFixtures::Person.create(:password => 'password1')
12
12
 
13
- @people = DataMapper::Types::Fixtures::Person.all
13
+ @people = DataMapper::TypesFixtures::Person.all
14
14
  @resource.reload
15
15
  end
16
16
 
@@ -4,10 +4,10 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/person'
6
6
 
7
- describe DataMapper::Types::Fixtures::Person do
7
+ describe DataMapper::TypesFixtures::Person do
8
8
  supported_by :all do
9
9
  before :all do
10
- @resource = DataMapper::Types::Fixtures::Person.new(:name => '')
10
+ @resource = DataMapper::TypesFixtures::Person.new(:name => '')
11
11
  end
12
12
 
13
13
  describe 'with no interests information' do
@@ -4,11 +4,11 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/ticket'
6
6
 
7
- describe DataMapper::Types::Fixtures::Ticket do
7
+ describe DataMapper::TypesFixtures::Ticket do
8
8
  supported_by :all do
9
9
  describe 'that is dumped and then loaded' do
10
10
  before :all do
11
- @resource = DataMapper::Types::Fixtures::Ticket.new(
11
+ @resource = DataMapper::TypesFixtures::Ticket.new(
12
12
  :title => "Can't order by aggregated fields",
13
13
  :id => 789,
14
14
  :body => "I'm trying to use the aggregate method and sort the results by a summed field, but it doesn't work.",
@@ -26,7 +26,7 @@ try_spec do
26
26
 
27
27
  describe 'that is supplied a matching enumeration value' do
28
28
  before :all do
29
- @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :assigned)
29
+ @resource = DataMapper::TypesFixtures::Ticket.new(:status => :assigned)
30
30
  end
31
31
 
32
32
  it 'typecasts it for outside reader' do
@@ -36,7 +36,7 @@ try_spec do
36
36
 
37
37
  describe '#get' do
38
38
  before :all do
39
- @resource = DataMapper::Types::Fixtures::Ticket.new(
39
+ @resource = DataMapper::TypesFixtures::Ticket.new(
40
40
  :title => '"sudo make install" of drizzle fails because it tries to chown mysql',
41
41
  :id => 257497,
42
42
  :body => "Note that at the very least, there should be a check to see whether or not the user is created before chown'ing a file to the user.",
@@ -46,19 +46,19 @@ try_spec do
46
46
  end
47
47
 
48
48
  it 'supports queries with equality operator on enumeration property' do
49
- DataMapper::Types::Fixtures::Ticket.all(:status => :confirmed).
49
+ DataMapper::TypesFixtures::Ticket.all(:status => :confirmed).
50
50
  should include(@resource)
51
51
  end
52
52
 
53
53
  it 'supports queries with inequality operator on enumeration property' do
54
- DataMapper::Types::Fixtures::Ticket.all(:status.not => :confirmed).
54
+ DataMapper::TypesFixtures::Ticket.all(:status.not => :confirmed).
55
55
  should_not include(@resource)
56
56
  end
57
57
  end
58
58
 
59
59
  describe 'with value unknown to enumeration property' do
60
60
  before :all do
61
- @resource = DataMapper::Types::Fixtures::Ticket.new(:status => :undecided)
61
+ @resource = DataMapper::TypesFixtures::Ticket.new(:status => :undecided)
62
62
  end
63
63
 
64
64
  # TODO: consider sharing shared spec exampels with dm-validations,
@@ -4,12 +4,12 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/software_package'
6
6
 
7
- describe DataMapper::Types::Fixtures::SoftwarePackage do
7
+ describe DataMapper::TypesFixtures::SoftwarePackage do
8
8
  supported_by :all do
9
9
  describe 'with source path at /var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb' do
10
10
  before :all do
11
11
  @source_path = '/var/cache/apt/archives/linux-libc-dev_2.6.28-11.40_i386.deb'
12
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
12
+ @resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
13
13
  end
14
14
 
15
15
  describe 'when is a new record' do
@@ -49,7 +49,7 @@ try_spec do
49
49
  describe 'with destination path at /usr/local' do
50
50
  before :all do
51
51
  @destination_path = '/usr/local'
52
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:destination_path => @destination_path)
52
+ @resource = DataMapper::TypesFixtures::SoftwarePackage.new(:destination_path => @destination_path)
53
53
  end
54
54
 
55
55
  describe 'when saved and reloaded' do
@@ -91,7 +91,7 @@ try_spec do
91
91
  describe 'with no (nil) source path' do
92
92
  before :all do
93
93
  @source_path = nil
94
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
94
+ @resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
95
95
  end
96
96
 
97
97
  describe 'when saved and reloaded' do
@@ -109,7 +109,7 @@ try_spec do
109
109
  describe 'with a blank source path' do
110
110
  before :all do
111
111
  @source_path = ''
112
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
112
+ @resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
113
113
  end
114
114
 
115
115
  describe 'when saved and reloaded' do
@@ -127,7 +127,7 @@ try_spec do
127
127
  describe 'with a source path assigned to an empty array' do
128
128
  before :all do
129
129
  @source_path = []
130
- @resource = DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
130
+ @resource = DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
131
131
  end
132
132
 
133
133
  describe 'when saved and reloaded' do
@@ -150,7 +150,7 @@ try_spec do
150
150
  describe 'when instantiated' do
151
151
  it 'raises an exception' do
152
152
  lambda do
153
- DataMapper::Types::Fixtures::SoftwarePackage.new(:source_path => @source_path)
153
+ DataMapper::TypesFixtures::SoftwarePackage.new(:source_path => @source_path)
154
154
  end.should raise_error(TypeError)
155
155
  end
156
156
  end
@@ -4,10 +4,10 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/tshirt'
6
6
 
7
- describe DataMapper::Types::Fixtures::TShirt do
7
+ describe DataMapper::TypesFixtures::TShirt do
8
8
  supported_by :all do
9
9
  before do
10
- @resource = DataMapper::Types::Fixtures::TShirt.new(
10
+ @resource = DataMapper::TypesFixtures::TShirt.new(
11
11
  :writing => 'Fork you',
12
12
  :has_picture => true,
13
13
  :picture => :octocat,
@@ -17,7 +17,7 @@ try_spec do
17
17
 
18
18
  describe 'with the default value' do
19
19
  it 'returns it as an array' do
20
- @resource.size.should eql([DataMapper::Types::Fixtures::TShirt.properties[:size].default])
20
+ @resource.size.should eql([DataMapper::TypesFixtures::TShirt.properties[:size].default])
21
21
  end
22
22
  end
23
23
 
@@ -14,10 +14,10 @@ try_spec do
14
14
 
15
15
  require './spec/fixtures/network_node'
16
16
 
17
- describe DataMapper::Types::Fixtures::NetworkNode do
17
+ describe DataMapper::TypesFixtures::NetworkNode do
18
18
  supported_by :all do
19
19
  before :all do
20
- @resource = DataMapper::Types::Fixtures::NetworkNode.new(
20
+ @resource = DataMapper::TypesFixtures::NetworkNode.new(
21
21
  :node_uuid => '25a44800-21c9-11de-8c30-0800200c9a66',
22
22
  :ip_address => nil,
23
23
  :cidr_subnet_bits => nil
@@ -4,10 +4,10 @@ try_spec do
4
4
 
5
5
  require './spec/fixtures/person'
6
6
 
7
- describe DataMapper::Types::Fixtures::Person do
7
+ describe DataMapper::TypesFixtures::Person do
8
8
  supported_by :all do
9
9
  before :all do
10
- @resource = DataMapper::Types::Fixtures::Person.new(:name => 'Thomas Edison')
10
+ @resource = DataMapper::TypesFixtures::Person.new(:name => 'Thomas Edison')
11
11
  end
12
12
 
13
13
  describe 'with no positions information' do
@@ -6,12 +6,12 @@ try_spec do
6
6
 
7
7
  require './spec/fixtures/article'
8
8
 
9
- describe DataMapper::Types::Fixtures::Article do
9
+ describe DataMapper::TypesFixtures::Article do
10
10
  supported_by :all do
11
11
  describe "persisted with title and slug set to 'New DataMapper Type'" do
12
12
  before :all do
13
13
  @input = 'New DataMapper Type'
14
- @resource = DataMapper::Types::Fixtures::Article.create(:title => @input, :slug => @input)
14
+ @resource = DataMapper::TypesFixtures::Article.create(:title => @input, :slug => @input)
15
15
 
16
16
  @resource.reload
17
17
  end
@@ -21,7 +21,7 @@ try_spec do
21
21
  end
22
22
 
23
23
  it 'can be found by slug' do
24
- DataMapper::Types::Fixtures::Article.first(:slug => 'new-datamapper-type').should == @resource
24
+ DataMapper::TypesFixtures::Article.first(:slug => 'new-datamapper-type').should == @resource
25
25
  end
26
26
  end
27
27
 
@@ -38,7 +38,7 @@ try_spec do
38
38
  ].each do |title, slug|
39
39
  describe "set with title '#{title}'" do
40
40
  before :all do
41
- @resource = DataMapper::Types::Fixtures::Article.new(:title => title)
41
+ @resource = DataMapper::TypesFixtures::Article.new(:title => title)
42
42
  @resource.valid?.should be(true)
43
43
  end
44
44
 
@@ -53,7 +53,7 @@ try_spec do
53
53
  end
54
54
 
55
55
  it 'can be found by slug' do
56
- DataMapper::Types::Fixtures::Article.first(:slug => slug).should == @resource
56
+ DataMapper::TypesFixtures::Article.first(:slug => slug).should == @resource
57
57
  end
58
58
  end
59
59
  end