committee 5.0.0 → 5.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 284c8c1198255435e959dcee2b92cb25c3d80dd5fe6d4622b8077a69525712ed
4
- data.tar.gz: b306ec0ad5e628d9cc7b6382781c4b710c99bedb127a7000edadf9d0e0b8fa84
3
+ metadata.gz: d38440a7b31b31d429a47b744f397333489d09dbae1dbf16bcd74dd01124d68d
4
+ data.tar.gz: a7d1b5a22c1f415c6eb2bae32b6666df4558c3361f7685c50926499e2e74575e
5
5
  SHA512:
6
- metadata.gz: 687d9a47d2a17786313bde939339d464a8d775795458b09ad7d7784bfa337f848a9ffabe240e9f39173c4466589c026f64a8eede768e7abfff4b01b2672339f5
7
- data.tar.gz: 4ee7781341de9ebafae28d01d98c0f72d54067c425f3ee10b221c4eb88da85e79b36853bbda4818b20348177f8d975103cc5be694ff7e8252a6634a856853b7c
6
+ metadata.gz: 5314750901b395a42cdb9efe6c3a2992bb67a4d7561a0937422d48574f7705944a0b7317ccc5b10eda510734a8dac2375eaf27c1932be26ea1000662b14cf31d
7
+ data.tar.gz: 2ec012b81b43e319df14fbaefeb72b38bc2f065358084d479e927d68c58734e44c6b3d252436dc3fcc296dbfeb0c7798105fb52f3aca7325904673f7cf9647e4
@@ -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
- case File.extname(schema_path)
40
- when '.json'
41
- load_from_json(schema_path, parser_options: parser_options)
42
- when '.yaml', '.yml'
43
- load_from_yaml(schema_path, parser_options: parser_options)
44
- else
45
- raise "Committee only supports the following file extensions: '.json', '.yaml', '.yml'"
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Committee
4
- VERSION = '5.0.0'.freeze
4
+ VERSION = '5.1.0'.freeze
5
5
  end
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.0.0
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: 2023-01-28 00:00:00.000000000 Z
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: '1.0'
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: '1.0'
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.3.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.