format_parser 0.20.0 → 0.20.1

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: e97554eb9bf6ca4a4ea76daa0f226c370f707e270931759375e9f6b72c1e7f40
4
- data.tar.gz: 946767ce39eb4a96420fd52852f514333baa33ec20d256241acc7208863aaf87
3
+ metadata.gz: 0d10f78d5d1a472fc6af704132ac8b98542a141de3d5b8a998faebfa5a994b30
4
+ data.tar.gz: 65636e308c67d8ccc3e3ff592e5cfe02bf5c105ac32b85d17825279211b362db
5
5
  SHA512:
6
- metadata.gz: 612b8b1af86329fce62e3eb035b30178485679a76516fcfe8a72c3785ef782855098609e7189559df2fd5929663d5b7ec3b7319e5e44a7048229aa13b5fc5dc9
7
- data.tar.gz: 8ffa31f8c498d72eb734b15d9b5de99c44742e1651a200b5484da8e7d5bc5bba5d52092a9b8b52d7374646265be2ecd0f0b4f06bc4798b4da9a16f83d3749512
6
+ metadata.gz: bec31abec6687c7b8dd57783da5e2aec175e1f538097b03eba095c49bd636fc38d562b21e3da1b2ca24f74caffb37b9953e139372ce30be19aea502947b532ca
7
+ data.tar.gz: 51e593f4c14049467f657e786a2c9d54f91713d1ab45badbdd67d27876e1b61f3542936cb184cb72f0885745673b8423ce4ceda5c0b5cdb4661f96ebf2f6d59e
@@ -1,3 +1,6 @@
1
+ ## 0.20.1
2
+ * Make sure EXIF results work correctly with ActiveSupport JSON encoders
3
+
1
4
  ## 0.20.0
2
5
  * Correctly tag the license on Rubygems as MIT (Hippocratic) for easier audit
3
6
 
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.20.0'
2
+ VERSION = '0.20.1'
3
3
  end
@@ -100,17 +100,7 @@ module FormatParser::EXIFParser
100
100
  end
101
101
 
102
102
  def to_json(*maybe_coder)
103
- # Let EXIF tags that come later overwrite the properties from the tags
104
- # that come earlier
105
- overlay = @multiple_exif_results.each_with_object({}) do |one_exif_frame, h|
106
- h.merge!(one_exif_frame.to_hash)
107
- end
108
- # Overwrite the orientation with our custom method implementation, because
109
- # it does reject 0-values.
110
- overlay[:orientation] = orientation
111
-
112
- sanitized = FormatParser::AttributesJSON._sanitize_json_value(overlay)
113
- sanitized.to_json(*maybe_coder)
103
+ to_hash.to_json(*maybe_coder)
114
104
  end
115
105
 
116
106
  def orientation_sym
@@ -135,10 +125,27 @@ module FormatParser::EXIFParser
135
125
  0 # If none were found - the orientation is unknown
136
126
  end
137
127
 
128
+ # ActiveSupport will attempt to call #to_hash first, and
129
+ # #to_hash is a decent default implementation to have
130
+ def to_hash
131
+ # Let EXIF tags that come later overwrite the properties from the tags
132
+ # that come earlier
133
+ overlay = @multiple_exif_results.each_with_object({}) do |one_exif_frame, h|
134
+ h.merge!(one_exif_frame.to_hash)
135
+ end
136
+ # Overwrite the orientation with our custom method implementation, because
137
+ # it does reject 0-values.
138
+ overlay[:orientation] = orientation
139
+
140
+ FormatParser::AttributesJSON._sanitize_json_value(overlay)
141
+ end
142
+
138
143
  private
139
144
 
140
- def respond_to_missing?(method_name)
141
- @multiple_exif_results.last.respond_to?(method_name)
145
+ # respond_to_missing? accepts 2 arguments: the method name symbol
146
+ # and whether the method being looked up can be private or not
147
+ def respond_to_missing?(method_name, include_private_methods)
148
+ @multiple_exif_results.last.respond_to?(method_name, include_private_methods)
142
149
  end
143
150
 
144
151
  def method_missing(*a)
@@ -14,6 +14,34 @@ describe FormatParser::EXIFParser do
14
14
  end
15
15
  end
16
16
 
17
+ describe 'EXIFStack' do
18
+ it 'supports respond_to? for methods it does not have' do
19
+ # Peculiar thing: we need to support respond_to?(:to_hash)
20
+ # for compatibility with ActiveSupport JSON output. When you call as_json
21
+ # on an object ActiveSupport implements that as_json method and will then
22
+ # call #as_json on the contained objects as necessary, _or_ call
23
+ # other methods if it thinks it is necessary.
24
+ #
25
+ # Although we _will_ be implementing to_hash specifically
26
+ # the respond_to_missing must be implemented correctly
27
+ stack = FormatParser::EXIFParser::EXIFStack.new([{}, {}])
28
+ expect(stack).not_to respond_to(:no_such_method__at_all)
29
+ end
30
+
31
+ it 'returns a Hash from #to_hash' do
32
+ first_fake_exif = double(orientation: 1, to_hash: {foo: 123, bar: 675})
33
+ second_fake_exif = double(orientation: 4, to_hash: {foo: 245})
34
+
35
+ stack = FormatParser::EXIFParser::EXIFStack.new([first_fake_exif, second_fake_exif])
36
+ stack_as_hash = stack.to_hash
37
+
38
+ # In this instance we DO need an actual type_check, because #to_hash
39
+ # is used by default type coercions in Ruby
40
+ expect(stack_as_hash).to be_kind_of(Hash)
41
+ expect(stack_as_hash).to eq(foo: 245, bar: 675, orientation: 4)
42
+ end
43
+ end
44
+
17
45
  it 'is able to deal with an orientation tag which a tuple value for orientation' do
18
46
  path = fixtures_dir + '/EXIF/double_orientation.exif.bin'
19
47
  exif_data = File.open(path, 'rb') do |f|
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.20.0
4
+ version: 0.20.1
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: 2019-12-13 00:00:00.000000000 Z
12
+ date: 2020-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ks