ardm-types 1.2.2

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 (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +51 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +3 -0
  7. data/Rakefile +4 -0
  8. data/ardm-types.gemspec +29 -0
  9. data/lib/ardm-types.rb +1 -0
  10. data/lib/dm-types/api_key.rb +30 -0
  11. data/lib/dm-types/bcrypt_hash.rb +34 -0
  12. data/lib/dm-types/comma_separated_list.rb +29 -0
  13. data/lib/dm-types/csv.rb +38 -0
  14. data/lib/dm-types/enum.rb +51 -0
  15. data/lib/dm-types/epoch_time.rb +41 -0
  16. data/lib/dm-types/file_path.rb +32 -0
  17. data/lib/dm-types/flag.rb +63 -0
  18. data/lib/dm-types/ip_address.rb +42 -0
  19. data/lib/dm-types/json.rb +50 -0
  20. data/lib/dm-types/paranoid/base.rb +55 -0
  21. data/lib/dm-types/paranoid_boolean.rb +23 -0
  22. data/lib/dm-types/paranoid_datetime.rb +22 -0
  23. data/lib/dm-types/regexp.rb +21 -0
  24. data/lib/dm-types/slug.rb +29 -0
  25. data/lib/dm-types/support/dirty_minder.rb +166 -0
  26. data/lib/dm-types/support/flags.rb +41 -0
  27. data/lib/dm-types/uri.rb +38 -0
  28. data/lib/dm-types/uuid.rb +74 -0
  29. data/lib/dm-types/version.rb +5 -0
  30. data/lib/dm-types/yaml.rb +41 -0
  31. data/lib/dm-types.rb +23 -0
  32. data/spec/fixtures/api_user.rb +14 -0
  33. data/spec/fixtures/article.rb +35 -0
  34. data/spec/fixtures/bookmark.rb +23 -0
  35. data/spec/fixtures/invention.rb +7 -0
  36. data/spec/fixtures/network_node.rb +36 -0
  37. data/spec/fixtures/person.rb +25 -0
  38. data/spec/fixtures/software_package.rb +33 -0
  39. data/spec/fixtures/ticket.rb +21 -0
  40. data/spec/fixtures/tshirt.rb +24 -0
  41. data/spec/integration/api_key_spec.rb +27 -0
  42. data/spec/integration/bcrypt_hash_spec.rb +47 -0
  43. data/spec/integration/comma_separated_list_spec.rb +87 -0
  44. data/spec/integration/dirty_minder_spec.rb +197 -0
  45. data/spec/integration/enum_spec.rb +80 -0
  46. data/spec/integration/epoch_time_spec.rb +61 -0
  47. data/spec/integration/file_path_spec.rb +160 -0
  48. data/spec/integration/flag_spec.rb +72 -0
  49. data/spec/integration/ip_address_spec.rb +153 -0
  50. data/spec/integration/json_spec.rb +72 -0
  51. data/spec/integration/slug_spec.rb +67 -0
  52. data/spec/integration/uri_spec.rb +139 -0
  53. data/spec/integration/uuid_spec.rb +102 -0
  54. data/spec/integration/yaml_spec.rb +69 -0
  55. data/spec/rcov.opts +6 -0
  56. data/spec/shared/flags_shared_spec.rb +37 -0
  57. data/spec/shared/identity_function_group.rb +5 -0
  58. data/spec/spec.opts +4 -0
  59. data/spec/spec_helper.rb +30 -0
  60. data/spec/unit/bcrypt_hash_spec.rb +155 -0
  61. data/spec/unit/csv_spec.rb +142 -0
  62. data/spec/unit/enum_spec.rb +126 -0
  63. data/spec/unit/epoch_time_spec.rb +74 -0
  64. data/spec/unit/file_path_spec.rb +87 -0
  65. data/spec/unit/flag_spec.rb +114 -0
  66. data/spec/unit/ip_address_spec.rb +121 -0
  67. data/spec/unit/json_spec.rb +144 -0
  68. data/spec/unit/paranoid_boolean_spec.rb +150 -0
  69. data/spec/unit/paranoid_datetime_spec.rb +154 -0
  70. data/spec/unit/regexp_spec.rb +63 -0
  71. data/spec/unit/uri_spec.rb +64 -0
  72. data/spec/unit/uuid_spec.rb +25 -0
  73. data/spec/unit/yaml_spec.rb +111 -0
  74. data/tasks/spec.rake +38 -0
  75. data/tasks/yard.rake +9 -0
  76. data/tasks/yardstick.rake +19 -0
  77. metadata +236 -0
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+ describe DataMapper::Property::Regexp do
5
+ before :all do
6
+ class ::User
7
+ include DataMapper::Resource
8
+ property :id, Serial
9
+ property :regexp, Regexp
10
+ end
11
+
12
+ @property = User.properties[:regexp]
13
+ end
14
+
15
+ describe '.load' do
16
+ describe 'when argument is a string' do
17
+ before :all do
18
+ @input = '[a-z]\d+'
19
+ @result = @property.load(@input)
20
+ end
21
+
22
+ it 'create a regexp instance from argument' do
23
+ @result.should == Regexp.new(@input)
24
+ end
25
+ end
26
+
27
+ describe 'when argument is nil' do
28
+ before :all do
29
+ @input = nil
30
+ @result = @property.load(@input)
31
+ end
32
+
33
+ it 'returns nil' do
34
+ @result.should be_nil
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '.dump' do
40
+ describe 'when argument is a regular expression' do
41
+ before :all do
42
+ @input = /\d+/
43
+ @result = @property.dump(@input)
44
+ end
45
+
46
+ it 'escapes the argument' do
47
+ @result.should == '\\d+'
48
+ end
49
+ end
50
+
51
+ describe 'when argument is nil' do
52
+ before :all do
53
+ @input = nil
54
+ @result = @property.dump(@input)
55
+ end
56
+
57
+ it 'returns nil' do
58
+ @result.should be_nil
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ require './spec/fixtures/bookmark'
4
+
5
+ try_spec do
6
+ describe DataMapper::Property::URI do
7
+ before do
8
+ @uri_str = 'http://example.com/path/to/resource/'
9
+ @uri = Addressable::URI.parse(@uri_str)
10
+
11
+ @property = DataMapper::TypesFixtures::Bookmark.properties[:uri]
12
+ end
13
+
14
+ describe '.dump' do
15
+ it 'returns the URI as a String' do
16
+ @property.dump(@uri).should == @uri_str
17
+ end
18
+
19
+ describe 'when given nil' do
20
+ it 'returns nil' do
21
+ @property.dump(nil).should be_nil
22
+ end
23
+ end
24
+
25
+ describe 'when given an empty string' do
26
+ it 'returns an empty URI' do
27
+ @property.dump('').should == ''
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '.load' do
33
+ it 'returns the URI as Addressable' do
34
+ @property.load(@uri_str).should == @uri
35
+ end
36
+
37
+ describe 'when given nil' do
38
+ it 'returns nil' do
39
+ @property.load(nil).should be_nil
40
+ end
41
+ end
42
+
43
+ describe 'if given an empty String' do
44
+ it 'returns an empty URI' do
45
+ @property.load('').should == Addressable::URI.parse('')
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '.typecast' do
51
+ describe 'given instance of Addressable::URI' do
52
+ it 'does nothing' do
53
+ @property.typecast(@uri).should == @uri
54
+ end
55
+ end
56
+
57
+ describe 'when given a string' do
58
+ it 'delegates to .load' do
59
+ @property.typecast(@uri_str).should == @uri
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ try_spec do
4
+ require './spec/fixtures/network_node'
5
+
6
+ describe DataMapper::Property::UUID do
7
+ before :all do
8
+ @property = DataMapper::TypesFixtures::NetworkNode.properties[:node_uuid]
9
+ @input = 'b0fc632e-d744-4821-afe3-4ea0701859ee'
10
+ @uuid = UUIDTools::UUID.random_create
11
+ end
12
+
13
+ describe '#valid?' do
14
+ describe "with a String" do
15
+ subject { @property.valid?(@input) }
16
+ it { subject.should be(true) }
17
+ end
18
+
19
+ describe "with a UUIDTools::UUID" do
20
+ subject { @property.valid?(@uuid) }
21
+ it { subject.should be(true) }
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+ require 'shared/identity_function_group'
3
+
4
+ try_spec do
5
+
6
+ require './spec/fixtures/person'
7
+
8
+ describe DataMapper::Property::Yaml do
9
+ before :all do
10
+ @property = DataMapper::TypesFixtures::Person.properties[:inventions]
11
+ end
12
+
13
+ describe '.load' do
14
+ describe 'when nil is provided' do
15
+ it 'returns nil' do
16
+ @property.load(nil).should be_nil
17
+ end
18
+ end
19
+
20
+ describe 'when YAML encoded primitive string is provided' do
21
+ it 'returns decoded value as Ruby string' do
22
+ @property.load("--- yaml string\n").should == 'yaml string'
23
+ end
24
+ end
25
+
26
+ describe 'when something else is provided' do
27
+ it 'raises ArgumentError with a meaningful message' do
28
+ lambda {
29
+ @property.load(:sym)
30
+ }.should raise_error(ArgumentError, '+value+ of a property of YAML type must be nil or a String')
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '.dump' do
36
+ describe 'when nil is provided' do
37
+ it 'returns nil' do
38
+ @property.dump(nil).should be_nil
39
+ end
40
+ end
41
+
42
+ describe 'when YAML encoded primitive string is provided' do
43
+ it 'does not do double encoding' do
44
+ YAML.load(@property.dump("--- yaml encoded string\n")).should == 'yaml encoded string'
45
+ end
46
+ end
47
+
48
+ describe 'when regular Ruby string is provided' do
49
+ it 'dumps argument to YAML' do
50
+ YAML.load(@property.dump('dump me (to yaml)')).should == 'dump me (to yaml)'
51
+ end
52
+ end
53
+
54
+ describe 'when Ruby array is provided' do
55
+ it 'dumps argument to YAML' do
56
+ YAML.load(@property.dump([ 1, 2, 3 ])).should == [ 1, 2, 3 ]
57
+ end
58
+ end
59
+
60
+ describe 'when Ruby hash is provided' do
61
+ it 'dumps argument to YAML' do
62
+ YAML.load(@property.dump({ :datamapper => 'Data access layer in Ruby' })).should == { :datamapper => 'Data access layer in Ruby' }
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '.typecast' do
68
+ class ::SerializeMe
69
+ attr_accessor :name
70
+ end
71
+
72
+ describe 'given a number' do
73
+ before :all do
74
+ @input = 15
75
+ @result = 15
76
+ end
77
+
78
+ it_should_behave_like 'identity function'
79
+ end
80
+
81
+ describe 'given an Array instance' do
82
+ before :all do
83
+ @input = ['dm-core', 'dm-more']
84
+ @result = ['dm-core', 'dm-more']
85
+ end
86
+
87
+ it_should_behave_like 'identity function'
88
+ end
89
+
90
+ describe 'given a Hash instance' do
91
+ before :all do
92
+ @input = { :format => 'yaml' }
93
+ @result = { :format => 'yaml' }
94
+ end
95
+
96
+ it_should_behave_like 'identity function'
97
+ end
98
+
99
+ describe 'given a plain old Ruby object' do
100
+ before :all do
101
+ @input = SerializeMe.new
102
+ @input.name = 'yamly'
103
+
104
+ @result = @input
105
+ end
106
+
107
+ it_should_behave_like 'identity function'
108
+ end
109
+ end
110
+ end
111
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,38 @@
1
+ spec_defaults = lambda do |spec|
2
+ spec.pattern = 'spec/**/*_spec.rb'
3
+ spec.libs << 'lib' << 'spec'
4
+ spec.spec_opts << '--options' << 'spec/spec.opts'
5
+ end
6
+
7
+ begin
8
+ require 'spec/rake/spectask'
9
+
10
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
11
+ rescue LoadError
12
+ task :spec do
13
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
14
+ end
15
+ end
16
+
17
+ begin
18
+ require 'rcov'
19
+ require 'spec/rake/verify_rcov'
20
+
21
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
22
+ spec_defaults.call(rcov)
23
+ rcov.rcov = true
24
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
25
+ end
26
+
27
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
28
+ rcov.threshold = 100
29
+ end
30
+ rescue LoadError
31
+ %w[ rcov verify_rcov ].each do |name|
32
+ task name do
33
+ abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
34
+ end
35
+ end
36
+ end
37
+
38
+ task :default => :spec
data/tasks/yard.rake ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'yard'
3
+
4
+ YARD::Rake::YardocTask.new
5
+ rescue LoadError
6
+ task :yard do
7
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'pathname'
3
+ require 'yardstick/rake/measurement'
4
+ require 'yardstick/rake/verify'
5
+
6
+ # yardstick_measure task
7
+ Yardstick::Rake::Measurement.new
8
+
9
+ # verify_measurements task
10
+ Yardstick::Rake::Verify.new do |verify|
11
+ verify.threshold = 100
12
+ end
13
+ rescue LoadError
14
+ %w[ yardstick_measure verify_measurements ].each do |name|
15
+ task name.to_s do
16
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ardm-types
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Martin Emde
8
+ - Dan Kubb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-01-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ardm-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bcrypt
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '3.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: fastercsv
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.5'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.5'
56
+ - !ruby/object:Gem::Dependency
57
+ name: multi_json
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: stringex
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.3'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.3'
84
+ - !ruby/object:Gem::Dependency
85
+ name: uuidtools
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '2.1'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '2.1'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '0.9'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.9'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - "~>"
117
+ - !ruby/object:Gem::Version
118
+ version: '1.3'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - "~>"
124
+ - !ruby/object:Gem::Version
125
+ version: '1.3'
126
+ description: Ardm fork of dm-types
127
+ email:
128
+ - me@martinemde.com
129
+ - dan.kubb@gmail.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files:
133
+ - LICENSE
134
+ - README.rdoc
135
+ files:
136
+ - ".gitignore"
137
+ - ".travis.yml"
138
+ - Gemfile
139
+ - LICENSE
140
+ - README.rdoc
141
+ - Rakefile
142
+ - ardm-types.gemspec
143
+ - lib/ardm-types.rb
144
+ - lib/dm-types.rb
145
+ - lib/dm-types/api_key.rb
146
+ - lib/dm-types/bcrypt_hash.rb
147
+ - lib/dm-types/comma_separated_list.rb
148
+ - lib/dm-types/csv.rb
149
+ - lib/dm-types/enum.rb
150
+ - lib/dm-types/epoch_time.rb
151
+ - lib/dm-types/file_path.rb
152
+ - lib/dm-types/flag.rb
153
+ - lib/dm-types/ip_address.rb
154
+ - lib/dm-types/json.rb
155
+ - lib/dm-types/paranoid/base.rb
156
+ - lib/dm-types/paranoid_boolean.rb
157
+ - lib/dm-types/paranoid_datetime.rb
158
+ - lib/dm-types/regexp.rb
159
+ - lib/dm-types/slug.rb
160
+ - lib/dm-types/support/dirty_minder.rb
161
+ - lib/dm-types/support/flags.rb
162
+ - lib/dm-types/uri.rb
163
+ - lib/dm-types/uuid.rb
164
+ - lib/dm-types/version.rb
165
+ - lib/dm-types/yaml.rb
166
+ - spec/fixtures/api_user.rb
167
+ - spec/fixtures/article.rb
168
+ - spec/fixtures/bookmark.rb
169
+ - spec/fixtures/invention.rb
170
+ - spec/fixtures/network_node.rb
171
+ - spec/fixtures/person.rb
172
+ - spec/fixtures/software_package.rb
173
+ - spec/fixtures/ticket.rb
174
+ - spec/fixtures/tshirt.rb
175
+ - spec/integration/api_key_spec.rb
176
+ - spec/integration/bcrypt_hash_spec.rb
177
+ - spec/integration/comma_separated_list_spec.rb
178
+ - spec/integration/dirty_minder_spec.rb
179
+ - spec/integration/enum_spec.rb
180
+ - spec/integration/epoch_time_spec.rb
181
+ - spec/integration/file_path_spec.rb
182
+ - spec/integration/flag_spec.rb
183
+ - spec/integration/ip_address_spec.rb
184
+ - spec/integration/json_spec.rb
185
+ - spec/integration/slug_spec.rb
186
+ - spec/integration/uri_spec.rb
187
+ - spec/integration/uuid_spec.rb
188
+ - spec/integration/yaml_spec.rb
189
+ - spec/rcov.opts
190
+ - spec/shared/flags_shared_spec.rb
191
+ - spec/shared/identity_function_group.rb
192
+ - spec/spec.opts
193
+ - spec/spec_helper.rb
194
+ - spec/unit/bcrypt_hash_spec.rb
195
+ - spec/unit/csv_spec.rb
196
+ - spec/unit/enum_spec.rb
197
+ - spec/unit/epoch_time_spec.rb
198
+ - spec/unit/file_path_spec.rb
199
+ - spec/unit/flag_spec.rb
200
+ - spec/unit/ip_address_spec.rb
201
+ - spec/unit/json_spec.rb
202
+ - spec/unit/paranoid_boolean_spec.rb
203
+ - spec/unit/paranoid_datetime_spec.rb
204
+ - spec/unit/regexp_spec.rb
205
+ - spec/unit/uri_spec.rb
206
+ - spec/unit/uuid_spec.rb
207
+ - spec/unit/yaml_spec.rb
208
+ - tasks/spec.rake
209
+ - tasks/yard.rake
210
+ - tasks/yardstick.rake
211
+ homepage: http://github.com/martinemde/ardm-types
212
+ licenses:
213
+ - MIT
214
+ metadata: {}
215
+ post_install_message:
216
+ rdoc_options: []
217
+ require_paths:
218
+ - lib
219
+ required_ruby_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ version: '0'
229
+ requirements: []
230
+ rubyforge_project:
231
+ rubygems_version: 2.2.2
232
+ signing_key:
233
+ specification_version: 4
234
+ summary: Ardm fork of dm-types
235
+ test_files: []
236
+ has_rdoc: