media_types 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d77ce12d19694083cf37f19ccf0c68b402abe672c5e50b0d322879e9600ebda2
4
- data.tar.gz: d2f90701ea7c0caf572e7565dcb47ff144ecc9255c81dadbe3d8264b6fcf1b30
3
+ metadata.gz: 015cccf33a3af68f0e282b1c95c7ffe7015ae4a889e8e20731a2abfcc80322f2
4
+ data.tar.gz: edbdf2641d03043cadfd60392ea9b092e902a4471febf95a7bccb3e926b69e58
5
5
  SHA512:
6
- metadata.gz: 273d09cee3e58708829d3d198d5178a88e86f79bd8ac414ba43587e0af756e1cf63dea66e4e9c4c98c1385b6b87363fabde907962417f24768b34168f1483c11
7
- data.tar.gz: 0fafe409b8b89eeb979177514c8e25df1641c90a165f88c577e2f933ddc3d858b3c46f7c17672fb96ae2f3b0244bae40824ac53e66c7a46b87dcb206be8e65b4
6
+ metadata.gz: 8d55fd91afc2be432ccc7842d8b53df3a6f8190d487111f49c04386b77678d5b88088406f7d40bc1535aebe48af6617edcab46141689f57759d5430e75d94db7
7
+ data.tar.gz: '09f57d4eeee475e1dc40aff213128bee1b69a35b166d7e055f3a60146d77972723c2feafeae6fecb58e87910fbac8e9cafbdc1f3690940863476f90cc54f48f4'
@@ -0,0 +1,42 @@
1
+ name: Debian
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-18.04
13
+
14
+ steps:
15
+ - uses: actions/checkout@v1
16
+ - name: Install dependencies
17
+ run: |
18
+ sudo apt-get update
19
+ DEBIAN_FRONTEND=noninteractive sudo apt-get --yes install gem2deb bundler ruby-{actionpack,awesome-print,http,minitest,minitest-reporters,oj,simplecov}
20
+ rm Gemfile.lock || true
21
+ bundle install --local
22
+ sudo apt-file update
23
+ - name: Build
24
+ run: |
25
+ bundle exec rake build
26
+ mkdir debpkg
27
+ cp pkg/media_types-*.gem media_types.gem
28
+ #(cd debpkg; gem2tgz media_types.gem)
29
+ #(cd debpkg; dh-make-ruby media_types-*.tar.gz)
30
+ #(cd debpkg; dh-make-ruby media_types-*.tar.gz)
31
+ (cd pkg; gem2deb media_types*.gem)
32
+ mv pkg/ruby-media-types_*_all.deb ruby-media-types.deb
33
+ - name: Upload gem
34
+ uses: actions/upload-artifact@v1
35
+ with:
36
+ name: media_types.gem
37
+ path: media_types.gem
38
+ - name: Upload deb
39
+ uses: actions/upload-artifact@v1
40
+ with:
41
+ name: ruby-media-types.deb
42
+ path: ruby-media-types.deb
@@ -15,6 +15,8 @@ jobs:
15
15
  ruby-version: 2.6.x
16
16
  - name: Build and test with Rake
17
17
  run: |
18
- gem install bundler
18
+ sudo apt-get update
19
+ DEBIAN_FRONTEND=noninteractive sudo apt-get install --yes bundler
20
+ rm Gemfile.lock || true
19
21
  bundle install --jobs 4 --retry 3
20
22
  bundle exec rake
@@ -1,3 +1,9 @@
1
+ # 2.0.1
2
+
3
+ - Views can now be accessed indifferently.
4
+ - Attribute keys no longer match indifferently.
5
+ - Fixed infinite loop when validating non-hash, non-array items.
6
+
1
7
  # 2.0.0
2
8
 
3
9
  - Removed ability to set default suffix. All suffixes now default to `+json`.
@@ -1,64 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types (2.0.0)
4
+ media_types (2.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- addressable (2.7.0)
10
- public_suffix (>= 2.0.2, < 5.0)
11
9
  ansi (1.5.0)
12
10
  awesome_print (1.8.0)
13
11
  builder (3.2.4)
14
12
  docile (1.3.2)
15
- domain_name (0.5.20190701)
16
- unf (>= 0.0.5, < 1.0.0)
17
- ffi (1.12.2)
18
- ffi-compiler (1.0.1)
19
- ffi (>= 1.0.0)
20
- rake
21
- http (4.3.0)
22
- addressable (~> 2.3)
23
- http-cookie (~> 1.0)
24
- http-form_data (~> 2.2)
25
- http-parser (~> 1.2.0)
26
- http-cookie (1.0.3)
27
- domain_name (~> 0.5)
28
- http-form_data (2.2.0)
29
- http-parser (1.2.1)
30
- ffi-compiler (>= 1.0, < 2.0)
31
13
  minitest (5.14.0)
32
- minitest-ci (3.4.0)
33
- minitest (>= 5.0.6)
34
14
  minitest-reporters (1.4.2)
35
15
  ansi
36
16
  builder
37
17
  minitest (>= 5.0)
38
18
  ruby-progressbar
39
- public_suffix (4.0.3)
19
+ oj (3.10.5)
40
20
  rake (13.0.1)
41
21
  ruby-progressbar (1.10.1)
42
22
  simplecov (0.18.5)
43
23
  docile (~> 1.1)
44
24
  simplecov-html (~> 0.11)
45
25
  simplecov-html (0.12.2)
46
- unf (0.1.4)
47
- unf_ext
48
- unf_ext (0.0.7.6)
49
26
 
50
27
  PLATFORMS
51
28
  ruby
52
29
 
53
30
  DEPENDENCIES
54
31
  awesome_print
55
- bundler
56
- http
32
+ bundler (>= 1.16.1)
57
33
  media_types!
58
34
  minitest (~> 5.0)
59
- minitest-ci
60
35
  minitest-reporters
61
- rake (~> 13.0)
36
+ oj
37
+ rake (>= 12.0)
62
38
  simplecov
63
39
 
64
40
  BUNDLED WITH
@@ -69,7 +69,7 @@ module MediaTypes
69
69
  end
70
70
 
71
71
  def as_key
72
- [type, view, version]
72
+ [type, view&.to_s, version]
73
73
  end
74
74
 
75
75
  def hash
@@ -115,7 +115,7 @@ module MediaTypes
115
115
 
116
116
  def validations(&block)
117
117
  unless block_given?
118
- raise 'No validations defined' if media_type_validations.nil?
118
+ raise "No validations defined for #{self.name}" if media_type_validations.nil?
119
119
  return media_type_validations
120
120
  end
121
121
  self.media_type_validations = Validations.new(to_constructable, &block)
@@ -159,6 +159,11 @@ module MediaTypes
159
159
  # # => true
160
160
  #
161
161
  def attribute(key, type = ::Object, optional: false, **opts, &block)
162
+ raise KeyTypeError, "Unexpected key type #{key.class.name}, please use either a symbol or string." unless key.is_a?(String) || key.is_a?(Symbol)
163
+ raise DuplicateKeyError, "An attribute with key #{key.to_s} has already been defined. Please remove one of the two." if rules.has_key?(key)
164
+ raise DuplicateKeyError, "A string attribute with the same string representation as the symbol :#{key.to_s} already exists. Please remove one of the two." if key.is_a?(Symbol)&& rules.has_key?(key.to_s)
165
+ raise DuplicateKeyError, "A symbol attribute with the same string representation as the string '#{key}' already exists. Please remove one of the two." if key.is_a?(String) && rules.has_key?(key.to_sym)
166
+
162
167
  if block_given?
163
168
  return collection(key, expected_type: ::Hash, optional: optional, **opts, &block)
164
169
  end
@@ -380,13 +385,13 @@ module MediaTypes
380
385
  end
381
386
 
382
387
  def assert_pass(fixture)
383
- json = JSON.parse(fixture)
388
+ json = JSON.parse(fixture, { symbolize_names: true })
384
389
 
385
390
  validate(json)
386
391
  end
387
392
 
388
393
  def assert_fail(fixture)
389
- json = JSON.parse(fixture)
394
+ json = JSON.parse(fixture, { symbolize_names: true })
390
395
 
391
396
  begin
392
397
  validate(json)
@@ -6,6 +6,12 @@ module MediaTypes
6
6
  # Base class for all validations errors
7
7
  class ValidationError < ArgumentError; end
8
8
 
9
+ # Raised when trying to register an attribute with a non-string key
10
+ class KeyTypeError < ArgumentError; end
11
+
12
+ # Raised when trying to register a key twice
13
+ class DuplicateKeyError < ArgumentError; end
14
+
9
15
  # Raised when it did not expect more data, but there was more left
10
16
  class StrictValidationError < ValidationError; end
11
17
 
@@ -22,8 +22,8 @@ module MediaTypes
22
22
  '%<found>s',
23
23
  key: key.inspect,
24
24
  backtrace: backtrace.join('->'),
25
- strict_keys: strict_keys.keys,
26
- found: (found.is_a? Hash) ? found.keys : found.class.name
25
+ strict_keys: keys_to_str(strict_keys.keys),
26
+ found: (found.respond_to? :keys) ? keys_to_str(found.keys) : found.class.name
27
27
  )
28
28
  end
29
29
 
@@ -31,6 +31,11 @@ module MediaTypes
31
31
  '((raise when strict))'
32
32
  end
33
33
 
34
+ def keys_to_str(keys)
35
+ converted = keys.map { |k| k.is_a?(Symbol) ? ":#{k}" : "'#{k}'" }
36
+ "[#{converted.join ', '}]"
37
+ end
38
+
34
39
  end
35
40
  end
36
41
  end
@@ -26,7 +26,11 @@ module MediaTypes
26
26
  return iterate_hash { |*args, **opts| yield(*args, **opts) }
27
27
  end
28
28
 
29
- iterate { |*args, **opts| yield(*args, **opts) }
29
+ if array?
30
+ return iterate { |*args, **opts| yield(*args, **opts) }
31
+ end
32
+
33
+ raise "Internal consistency error, unexpected: #{enumerable.class}"
30
34
  end
31
35
 
32
36
  private
@@ -37,6 +41,10 @@ module MediaTypes
37
41
  enumerable.is_a?(::Hash) || enumerable.respond_to?(:key)
38
42
  end
39
43
 
44
+ def array?
45
+ enumerable.is_a?(::Array)
46
+ end
47
+
40
48
  def iterate_hash
41
49
  context = EnumerationContext.new(rules: rules)
42
50
 
@@ -46,7 +54,10 @@ module MediaTypes
46
54
  end
47
55
 
48
56
  def iterate(&block)
49
- Array(enumerable).each_with_index.all? do |array_like_element, i|
57
+ hash_rule = Rules.new(allow_empty: false, expected_type: ::Hash)
58
+
59
+ enumerable.each_with_index.all? do |array_like_element, i|
60
+ OutputTypeGuard.call(array_like_element, options.trace(1), rules: hash_rule)
50
61
  OutputIteratorWithPredicate.call(array_like_element, options.trace(i), rules: rules, &block)
51
62
  end
52
63
  end
@@ -18,6 +18,8 @@ module MediaTypes
18
18
  end
19
19
 
20
20
  def call
21
+ #puts @rules
22
+ #puts "input: <#{output}>, type: <#{expected_type.name}>"
21
23
  return unless expected_type && !(expected_type === output) # rubocop:disable Style/CaseEquality
22
24
  raise_type_error!(type: output.class, backtrace: options.backtrace)
23
25
  end
@@ -114,7 +114,8 @@ module MediaTypes
114
114
  attr_writer :expected_type
115
115
 
116
116
  def normalize_key(key)
117
- String(key).to_sym
117
+ # Because default ruby hashes don't treat symbols and string equal we can't normalize them here.
118
+ key
118
119
  end
119
120
  end
120
121
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MediaTypes
4
- VERSION = '2.0.0'
4
+ VERSION = '2.0.1'
5
5
  end
@@ -24,11 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_development_dependency 'awesome_print'
27
- spec.add_development_dependency 'bundler'
28
- spec.add_development_dependency 'http'
27
+ spec.add_development_dependency 'bundler', '>= 1.16.1'
29
28
  spec.add_development_dependency 'minitest', '~> 5.0'
30
- spec.add_development_dependency 'minitest-ci'
31
29
  spec.add_development_dependency 'minitest-reporters'
32
- spec.add_development_dependency 'rake', '~> 13.0'
30
+ spec.add_development_dependency 'oj'
31
+ spec.add_development_dependency 'rake', '>= 12.0'
33
32
  spec.add_development_dependency 'simplecov'
34
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-03-28 00:00:00.000000000 Z
12
+ date: 2020-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -31,28 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: 1.16.1
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: http
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
41
+ version: 1.16.1
56
42
  - !ruby/object:Gem::Dependency
57
43
  name: minitest
58
44
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ dependencies:
68
54
  - !ruby/object:Gem::Version
69
55
  version: '5.0'
70
56
  - !ruby/object:Gem::Dependency
71
- name: minitest-ci
57
+ name: minitest-reporters
72
58
  requirement: !ruby/object:Gem::Requirement
73
59
  requirements:
74
60
  - - ">="
@@ -82,7 +68,7 @@ dependencies:
82
68
  - !ruby/object:Gem::Version
83
69
  version: '0'
84
70
  - !ruby/object:Gem::Dependency
85
- name: minitest-reporters
71
+ name: oj
86
72
  requirement: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - ">="
@@ -99,16 +85,16 @@ dependencies:
99
85
  name: rake
100
86
  requirement: !ruby/object:Gem::Requirement
101
87
  requirements:
102
- - - "~>"
88
+ - - ">="
103
89
  - !ruby/object:Gem::Version
104
- version: '13.0'
90
+ version: '12.0'
105
91
  type: :development
106
92
  prerelease: false
107
93
  version_requirements: !ruby/object:Gem::Requirement
108
94
  requirements:
109
- - - "~>"
95
+ - - ">="
110
96
  - !ruby/object:Gem::Version
111
- version: '13.0'
97
+ version: '12.0'
112
98
  - !ruby/object:Gem::Dependency
113
99
  name: simplecov
114
100
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +118,7 @@ executables: []
132
118
  extensions: []
133
119
  extra_rdoc_files: []
134
120
  files:
121
+ - ".github/workflows/debian.yml"
135
122
  - ".github/workflows/ruby.yml"
136
123
  - ".gitignore"
137
124
  - ".rubocop.yml"