format_parser 0.25.5 → 0.25.6

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: c39f9a0aae6e1474bbe2e3ff845ebf6c349e042510a4e8049384bfcdb7506c33
4
- data.tar.gz: 604732d31301b227844649b82b3c4e13aa5dddcab1158cfea51abc7998ebd26e
3
+ metadata.gz: dbc915cd212f2207b6f54cc4b567ea342a0bfd76af1e5e3db23330a6cc879e27
4
+ data.tar.gz: 0a623b8303cbf40a58d348b4e1adcda2d6fc0170b411fba529f9d3ae53533282
5
5
  SHA512:
6
- metadata.gz: 189c3e155e868475ce45cbd4576f2d381452b74a1718962f9a306915837d415ccb699b5e8bb0c84b282013890a6a1b4a4e873227525154e577b39e9c6e7f31d9
7
- data.tar.gz: c300a554bb9c2328abafe79ca560de504b6684e96a4a97b698bc8c555085bd0a423792965cb1d323306108be47bf7e238af3bc0e44bb858c0af5aaef9d45546e
6
+ metadata.gz: 0ed65c67f508264c0c6c12e88287266ef2bb9346c7e44934ac2e8ac97001de8f5e7f605bdd497ee6f95a45bcf4ad7f6b69021d25739e85debafaecfca76153ce
7
+ data.tar.gz: 4b250cd8f41bbba735e5d90a4a829c4fea699f04dd190a37499853ed48475aecd19f6d32360f081474355a4f5f9c562e1ca78e8c7c8aba91e5fb9e0ca4930299
@@ -1,3 +1,6 @@
1
+ ## 0.25.6
2
+ * Fix FormatParser.parse (with `results: :first`) to be deterministic
3
+
1
4
  ## 0.25.5
2
5
  * DPX: Fix DPXParser to support images without aspect ratio
3
6
 
@@ -49,8 +49,10 @@ module FormatParser
49
49
  parser_provided_formats = Array(formats)
50
50
  parser_provided_natures = Array(natures)
51
51
  PARSER_MUX.synchronize do
52
- @parsers ||= Set.new
53
- @parsers << callable_parser
52
+ # It can't be a Set because the method `parsers_for` depends on the order
53
+ # that the parsers were added.
54
+ @parsers ||= []
55
+ @parsers << callable_parser unless @parsers.include?(callable_parser)
54
56
  @parsers_per_nature ||= {}
55
57
  parser_provided_natures.each do |provided_nature|
56
58
  @parsers_per_nature[provided_nature] ||= Set.new
@@ -255,7 +257,19 @@ module FormatParser
255
257
  # Order the parsers according to their priority value. The ones having a lower
256
258
  # value will sort higher and will be applied sooner
257
259
  parsers_in_order_of_priority = parsers.to_a.sort do |parser_a, parser_b|
258
- @parser_priorities[parser_a] <=> @parser_priorities[parser_b]
260
+ if @parser_priorities[parser_a] != @parser_priorities[parser_b]
261
+ @parser_priorities[parser_a] <=> @parser_priorities[parser_b]
262
+ else
263
+ # Some parsers have the same priority and we want them to be always sorted
264
+ # in the same way, to not change the result of FormatParser.parse(results: :first).
265
+ # When this changes, it can generate flaky tests or event different
266
+ # results in different environments, which can be hard to understand why.
267
+ # There is also no guarantee in the order that the elements are added in
268
+ # @@parser_priorities
269
+ # So, to have always the same order, we sort by the order that the parsers
270
+ # were registered if the priorities are the same.
271
+ @parsers.index(parser_a) <=> @parsers.index(parser_b)
272
+ end
259
273
  end
260
274
 
261
275
  # If there is one parser that is more likely to match, place it first
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.25.5'
2
+ VERSION = '0.25.6'
3
3
  end
@@ -173,6 +173,26 @@ describe FormatParser do
173
173
  prioritized_parsers = FormatParser.parsers_for([:archive, :document, :image, :audio], [:tif, :jpg, :zip, :docx, :mp3, :aiff], 'a-file.zip')
174
174
  expect(prioritized_parsers.first).to be_kind_of(FormatParser::ZIPParser)
175
175
  end
176
+
177
+ it 'sorts the parsers by priority and name' do
178
+ parsers = FormatParser.parsers_for(
179
+ [:audio, :image],
180
+ [:cr2, :dpx, :fdx, :flac, :gif, :jpg, :mov, :mp4, :m4a, :mp3, :mpg, :mpeg, :ogg, :png, :tif, :wav]
181
+ )
182
+
183
+ expect(parsers.map { |parser| parser.class.name }).to eq([
184
+ 'FormatParser::GIFParser',
185
+ 'Class',
186
+ 'FormatParser::PNGParser',
187
+ 'FormatParser::CR2Parser',
188
+ 'FormatParser::DPXParser',
189
+ 'FormatParser::FLACParser',
190
+ 'FormatParser::MP3Parser',
191
+ 'FormatParser::OggParser',
192
+ 'FormatParser::TIFFParser',
193
+ 'FormatParser::WAVParser'
194
+ ])
195
+ end
176
196
  end
177
197
 
178
198
  describe '.register_parser and .deregister_parser' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.5
4
+ version: 0.25.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-12-11 00:00:00.000000000 Z
12
+ date: 2020-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks
@@ -292,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
292
292
  - !ruby/object:Gem::Version
293
293
  version: '0'
294
294
  requirements: []
295
- rubygems_version: 3.0.3
295
+ rubygems_version: 3.1.4
296
296
  signing_key:
297
297
  specification_version: 4
298
298
  summary: A library for efficient parsing of file metadata