sbf-dm-types 1.3.0.beta

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 (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +45 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +468 -0
  5. data/.travis.yml +52 -0
  6. data/Gemfile +67 -0
  7. data/LICENSE +20 -0
  8. data/README.rdoc +3 -0
  9. data/Rakefile +4 -0
  10. data/dm-types.gemspec +26 -0
  11. data/lib/dm-types/api_key.rb +30 -0
  12. data/lib/dm-types/bcrypt_hash.rb +33 -0
  13. data/lib/dm-types/comma_separated_list.rb +28 -0
  14. data/lib/dm-types/csv.rb +34 -0
  15. data/lib/dm-types/enum.rb +55 -0
  16. data/lib/dm-types/epoch_time.rb +35 -0
  17. data/lib/dm-types/file_path.rb +24 -0
  18. data/lib/dm-types/flag.rb +64 -0
  19. data/lib/dm-types/ip_address.rb +34 -0
  20. data/lib/dm-types/json.rb +48 -0
  21. data/lib/dm-types/paranoid/base.rb +56 -0
  22. data/lib/dm-types/paranoid_boolean.rb +23 -0
  23. data/lib/dm-types/paranoid_datetime.rb +22 -0
  24. data/lib/dm-types/regexp.rb +21 -0
  25. data/lib/dm-types/slug.rb +28 -0
  26. data/lib/dm-types/support/dirty_minder.rb +168 -0
  27. data/lib/dm-types/support/flags.rb +41 -0
  28. data/lib/dm-types/uri.rb +27 -0
  29. data/lib/dm-types/uuid.rb +64 -0
  30. data/lib/dm-types/version.rb +5 -0
  31. data/lib/dm-types/yaml.rb +39 -0
  32. data/lib/dm-types.rb +23 -0
  33. data/spec/fixtures/api_user.rb +14 -0
  34. data/spec/fixtures/article.rb +35 -0
  35. data/spec/fixtures/bookmark.rb +23 -0
  36. data/spec/fixtures/invention.rb +7 -0
  37. data/spec/fixtures/network_node.rb +36 -0
  38. data/spec/fixtures/person.rb +25 -0
  39. data/spec/fixtures/software_package.rb +33 -0
  40. data/spec/fixtures/ticket.rb +21 -0
  41. data/spec/fixtures/tshirt.rb +24 -0
  42. data/spec/integration/api_key_spec.rb +27 -0
  43. data/spec/integration/bcrypt_hash_spec.rb +47 -0
  44. data/spec/integration/comma_separated_list_spec.rb +87 -0
  45. data/spec/integration/dirty_minder_spec.rb +197 -0
  46. data/spec/integration/enum_spec.rb +78 -0
  47. data/spec/integration/epoch_time_spec.rb +61 -0
  48. data/spec/integration/file_path_spec.rb +160 -0
  49. data/spec/integration/flag_spec.rb +72 -0
  50. data/spec/integration/ip_address_spec.rb +153 -0
  51. data/spec/integration/json_spec.rb +72 -0
  52. data/spec/integration/slug_spec.rb +67 -0
  53. data/spec/integration/uri_spec.rb +117 -0
  54. data/spec/integration/uuid_spec.rb +102 -0
  55. data/spec/integration/yaml_spec.rb +87 -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_helper.rb +30 -0
  59. data/spec/unit/bcrypt_hash_spec.rb +155 -0
  60. data/spec/unit/csv_spec.rb +142 -0
  61. data/spec/unit/dirty_minder_spec.rb +65 -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 +75 -0
  65. data/spec/unit/flag_spec.rb +114 -0
  66. data/spec/unit/ip_address_spec.rb +109 -0
  67. data/spec/unit/json_spec.rb +126 -0
  68. data/spec/unit/paranoid_boolean_spec.rb +149 -0
  69. data/spec/unit/paranoid_datetime_spec.rb +153 -0
  70. data/spec/unit/regexp_spec.rb +63 -0
  71. data/spec/unit/uri_spec.rb +83 -0
  72. data/spec/unit/yaml_spec.rb +111 -0
  73. data/tasks/spec.rake +21 -0
  74. data/tasks/yard.rake +9 -0
  75. data/tasks/yardstick.rake +19 -0
  76. metadata +229 -0
@@ -0,0 +1,83 @@
1
+ require_relative '../spec_helper'
2
+
3
+ require_relative '../fixtures/bookmark'
4
+
5
+ try_spec do
6
+ describe DataMapper::Property::URI do
7
+ subject { DataMapper::TypesFixtures::Bookmark.properties[:uri] }
8
+
9
+ let(:uri) { Addressable::URI.parse(uri_str) }
10
+ let(:uri_str) { 'http://example.com/path/to/resource/' }
11
+
12
+ it { is_expected.to be_instance_of(described_class) }
13
+
14
+ describe '.dump' do
15
+ context 'with an instance of Addressable::URI' do
16
+ it 'returns the URI as a String' do
17
+ expect(subject.dump(uri)).to eql(uri_str)
18
+ end
19
+ end
20
+
21
+ context 'with nil' do
22
+ it 'returns nil' do
23
+ expect(subject.dump(nil)).to be(nil)
24
+ end
25
+ end
26
+
27
+ context 'with an empty string' do
28
+ it 'returns an empty URI' do
29
+ expect(subject.dump('')).to eql('')
30
+ end
31
+ end
32
+ end
33
+
34
+ describe '.load' do
35
+ context 'with a string' do
36
+ it 'returns the URI as an Addressable::URI' do
37
+ expect(subject.load(uri_str)).to eql(uri)
38
+ end
39
+ end
40
+
41
+ context 'with nil' do
42
+ it 'returns nil' do
43
+ expect(subject.load(nil)).to be(nil)
44
+ end
45
+ end
46
+
47
+ context 'with an empty string' do
48
+ it 'returns an empty URI' do
49
+ expect(subject.load('')).to eql(Addressable::URI.parse(''))
50
+ end
51
+ end
52
+
53
+ context 'with a non-normalized URI' do
54
+ let(:uri_str) { 'http://www.example.com:80' }
55
+ let(:uri) { Addressable::URI.parse('http://www.example.com/') }
56
+
57
+ it 'returns the URI as a normalized Addressable::URI' do
58
+ expect(subject.load(uri_str)).to eql(uri)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '.typecast' do
64
+ context 'with an instance of Addressable::URI' do
65
+ it 'does nothing' do
66
+ expect(subject.typecast(uri)).to eql(uri)
67
+ end
68
+ end
69
+
70
+ context 'with a string' do
71
+ it 'delegates to .load' do
72
+ expect(subject.typecast(uri_str)).to eql(uri)
73
+ end
74
+ end
75
+
76
+ context 'with nil' do
77
+ it 'returns nil' do
78
+ expect(subject.typecast(nil)).to be(nil)
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,111 @@
1
+ require_relative '../spec_helper'
2
+ require_relative '../shared/identity_function_group'
3
+
4
+ try_spec do
5
+
6
+ require_relative '../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
+ expect(@property.load(nil)).to 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
+ expect(@property.load("--- yaml string\n")).to eq '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
+ expect {
29
+ @property.load(:sym)
30
+ }.to 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
+ expect(@property.dump(nil)).to 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
+ expect(YAML.safe_load(@property.dump("--- yaml encoded string\n"))).to eq '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
+ expect(YAML.safe_load(@property.dump('dump me (to yaml)'))).to eq '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
+ expect(YAML.safe_load(@property.dump([ 1, 2, 3 ]))).to eq [ 1, 2, 3 ]
57
+ end
58
+ end
59
+
60
+ describe 'when Ruby hash is provided' do
61
+ it 'dumps argument to YAML' do
62
+ expect(YAML.safe_load(@property.dump('datamapper' => 'Data access layer in Ruby'))).to eq({ '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_behaves_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_behaves_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_behaves_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_behaves_like 'identity function'
108
+ end
109
+ end
110
+ end
111
+ end
data/tasks/spec.rake ADDED
@@ -0,0 +1,21 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ begin
4
+ task(:default).clear
5
+ task(:spec).clear
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.pattern = 'spec/**/*_spec.rb'
9
+
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ minimum_coverage 100
13
+ end
14
+ end
15
+ rescue LoadError
16
+ task :spec do
17
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
18
+ end
19
+ end
20
+
21
+ 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,229 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sbf-dm-types
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Dan Kubb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sbf-dm-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0.beta
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0.beta
41
+ - !ruby/object:Gem::Dependency
42
+ name: fastercsv
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.4
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.7.7
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.7'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.7.7
75
+ - !ruby/object:Gem::Dependency
76
+ name: safe_yaml
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.6.1
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.6.1
89
+ - !ruby/object:Gem::Dependency
90
+ name: stringex
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.0'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 2.0.8
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '2.0'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 2.0.8
109
+ - !ruby/object:Gem::Dependency
110
+ name: uuidtools
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 2.1.2
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: 2.1.2
123
+ description: DataMapper plugin providing extra data types for use in data models
124
+ email:
125
+ - dan.kubb@gmail.com
126
+ executables: []
127
+ extensions: []
128
+ extra_rdoc_files:
129
+ - LICENSE
130
+ - README.rdoc
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".rubocop.yml"
135
+ - ".travis.yml"
136
+ - Gemfile
137
+ - LICENSE
138
+ - README.rdoc
139
+ - Rakefile
140
+ - dm-types.gemspec
141
+ - lib/dm-types.rb
142
+ - lib/dm-types/api_key.rb
143
+ - lib/dm-types/bcrypt_hash.rb
144
+ - lib/dm-types/comma_separated_list.rb
145
+ - lib/dm-types/csv.rb
146
+ - lib/dm-types/enum.rb
147
+ - lib/dm-types/epoch_time.rb
148
+ - lib/dm-types/file_path.rb
149
+ - lib/dm-types/flag.rb
150
+ - lib/dm-types/ip_address.rb
151
+ - lib/dm-types/json.rb
152
+ - lib/dm-types/paranoid/base.rb
153
+ - lib/dm-types/paranoid_boolean.rb
154
+ - lib/dm-types/paranoid_datetime.rb
155
+ - lib/dm-types/regexp.rb
156
+ - lib/dm-types/slug.rb
157
+ - lib/dm-types/support/dirty_minder.rb
158
+ - lib/dm-types/support/flags.rb
159
+ - lib/dm-types/uri.rb
160
+ - lib/dm-types/uuid.rb
161
+ - lib/dm-types/version.rb
162
+ - lib/dm-types/yaml.rb
163
+ - spec/fixtures/api_user.rb
164
+ - spec/fixtures/article.rb
165
+ - spec/fixtures/bookmark.rb
166
+ - spec/fixtures/invention.rb
167
+ - spec/fixtures/network_node.rb
168
+ - spec/fixtures/person.rb
169
+ - spec/fixtures/software_package.rb
170
+ - spec/fixtures/ticket.rb
171
+ - spec/fixtures/tshirt.rb
172
+ - spec/integration/api_key_spec.rb
173
+ - spec/integration/bcrypt_hash_spec.rb
174
+ - spec/integration/comma_separated_list_spec.rb
175
+ - spec/integration/dirty_minder_spec.rb
176
+ - spec/integration/enum_spec.rb
177
+ - spec/integration/epoch_time_spec.rb
178
+ - spec/integration/file_path_spec.rb
179
+ - spec/integration/flag_spec.rb
180
+ - spec/integration/ip_address_spec.rb
181
+ - spec/integration/json_spec.rb
182
+ - spec/integration/slug_spec.rb
183
+ - spec/integration/uri_spec.rb
184
+ - spec/integration/uuid_spec.rb
185
+ - spec/integration/yaml_spec.rb
186
+ - spec/shared/flags_shared_spec.rb
187
+ - spec/shared/identity_function_group.rb
188
+ - spec/spec_helper.rb
189
+ - spec/unit/bcrypt_hash_spec.rb
190
+ - spec/unit/csv_spec.rb
191
+ - spec/unit/dirty_minder_spec.rb
192
+ - spec/unit/enum_spec.rb
193
+ - spec/unit/epoch_time_spec.rb
194
+ - spec/unit/file_path_spec.rb
195
+ - spec/unit/flag_spec.rb
196
+ - spec/unit/ip_address_spec.rb
197
+ - spec/unit/json_spec.rb
198
+ - spec/unit/paranoid_boolean_spec.rb
199
+ - spec/unit/paranoid_datetime_spec.rb
200
+ - spec/unit/regexp_spec.rb
201
+ - spec/unit/uri_spec.rb
202
+ - spec/unit/yaml_spec.rb
203
+ - tasks/spec.rake
204
+ - tasks/yard.rake
205
+ - tasks/yardstick.rake
206
+ homepage: https://datamapper.org
207
+ licenses:
208
+ - Nonstandard
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: 2.7.8
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">"
222
+ - !ruby/object:Gem::Version
223
+ version: 1.3.1
224
+ requirements: []
225
+ rubygems_version: 3.4.10
226
+ signing_key:
227
+ specification_version: 4
228
+ summary: DataMapper plugin providing extra data types
229
+ test_files: []