committee 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/committee/drivers.rb +23 -7
- data/lib/committee/version.rb +1 -1
- data/test/drivers_test.rb +29 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d38440a7b31b31d429a47b744f397333489d09dbae1dbf16bcd74dd01124d68d
|
4
|
+
data.tar.gz: a7d1b5a22c1f415c6eb2bae32b6666df4558c3361f7685c50926499e2e74575e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5314750901b395a42cdb9efe6c3a2992bb67a4d7561a0937422d48574f7705944a0b7317ccc5b10eda510734a8dac2375eaf27c1932be26ea1000662b14cf31d
|
7
|
+
data.tar.gz: 2ec012b81b43e319df14fbaefeb72b38bc2f065358084d479e927d68c58734e44c6b3d252436dc3fcc296dbfeb0c7798105fb52f3aca7325904673f7cf9647e4
|
data/lib/committee/drivers.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'digest'
|
4
|
+
|
3
5
|
module Committee
|
4
6
|
module Drivers
|
5
7
|
# Gets a driver instance from the specified name. Raises ArgumentError for
|
@@ -36,13 +38,16 @@ module Committee
|
|
36
38
|
# @param [String] schema_path
|
37
39
|
# @return [Committee::Driver]
|
38
40
|
def self.load_from_file(schema_path, parser_options: {})
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
@__load_from_file_cache ||= {}
|
42
|
+
@__load_from_file_cache[cache_key(schema_path, parser_options)] ||= begin
|
43
|
+
case File.extname(schema_path)
|
44
|
+
when '.json'
|
45
|
+
load_from_json(schema_path, parser_options: parser_options)
|
46
|
+
when '.yaml', '.yml'
|
47
|
+
load_from_yaml(schema_path, parser_options: parser_options)
|
48
|
+
else
|
49
|
+
raise "Committee only supports the following file extensions: '.json', '.yaml', '.yml'"
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
@@ -74,6 +79,17 @@ module Committee
|
|
74
79
|
# TODO: in the future, pass `opts` here and allow optionality in other drivers?
|
75
80
|
driver.parse(hash)
|
76
81
|
end
|
82
|
+
|
83
|
+
class << self
|
84
|
+
private
|
85
|
+
|
86
|
+
def cache_key(schema_path, parser_options)
|
87
|
+
[
|
88
|
+
File.exist?(schema_path) ? Digest::MD5.hexdigest(File.read(schema_path)) : nil,
|
89
|
+
parser_options.hash,
|
90
|
+
].join('_')
|
91
|
+
end
|
92
|
+
end
|
77
93
|
end
|
78
94
|
end
|
79
95
|
|
data/lib/committee/version.rb
CHANGED
data/test/drivers_test.rb
CHANGED
@@ -67,6 +67,35 @@ describe Committee::Drivers do
|
|
67
67
|
end
|
68
68
|
assert_equal "Committee only supports the following file extensions: '.json', '.yaml', '.yml'", e.message
|
69
69
|
end
|
70
|
+
|
71
|
+
describe 'cache behavior' do
|
72
|
+
describe 'when loading the same file' do
|
73
|
+
it 'returns the same object when the options are identical' do
|
74
|
+
assert_equal(
|
75
|
+
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
|
76
|
+
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns different objects if the options are different' do
|
81
|
+
refute_equal(
|
82
|
+
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
|
83
|
+
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: false}).object_id,
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns different objects if the file contents have changed' do
|
88
|
+
object_id = Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id
|
89
|
+
original_file_contents = File.read(open_api_3_schema_path)
|
90
|
+
File.write(open_api_3_schema_path, original_file_contents + "\n")
|
91
|
+
refute_equal(
|
92
|
+
Committee::Drivers.load_from_file(open_api_3_schema_path, parser_options:{strict_reference_validation: true}).object_id,
|
93
|
+
object_id,
|
94
|
+
)
|
95
|
+
File.write(open_api_3_schema_path, original_file_contents)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
70
99
|
end
|
71
100
|
|
72
101
|
describe 'load_from_json(schema_path)' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: committee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2024-01-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json_schema
|
@@ -52,14 +52,14 @@ dependencies:
|
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '2.0'
|
56
56
|
type: :runtime
|
57
57
|
prerelease: false
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '2.0'
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
64
|
name: minitest
|
65
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
321
|
- !ruby/object:Gem::Version
|
322
322
|
version: '0'
|
323
323
|
requirements: []
|
324
|
-
rubygems_version: 3.
|
324
|
+
rubygems_version: 3.4.20
|
325
325
|
signing_key:
|
326
326
|
specification_version: 4
|
327
327
|
summary: A collection of Rack middleware to support JSON Schema.
|