Class: Specdiff::Plugins::Json
- Inherits:
-
Object
- Object
- Specdiff::Plugins::Json
- Includes:
- Specdiff::Plugin
- Defined in:
- lib/specdiff/plugins/json.rb
Class Method Summary collapse
- ._json_parsable?(thing) ⇒ Boolean
- .compatible?(a, b) ⇒ Boolean
- .detect_type(thing) ⇒ Object
- .diff(a, b) ⇒ Object
- .id ⇒ Object
- .stringify(_diff) ⇒ Object
Methods included from Specdiff::Plugin
Class Method Details
._json_parsable?(thing) ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/specdiff/plugins/json.rb', line 14 def self._json_parsable?(thing) return false unless thing.is_a?(String) JSON.parse(thing) true rescue JSON::ParserError false end |
.compatible?(a, b) ⇒ Boolean
23 24 25 |
# File 'lib/specdiff/plugins/json.rb', line 23 def self.compatible?(a, b) a.type == :json || b.type == :json end |
.detect_type(thing) ⇒ Object
10 11 12 |
# File 'lib/specdiff/plugins/json.rb', line 10 def self.detect_type(thing) thing.is_a?(String) && _json_parsable?(thing) end |
.diff(a, b) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/specdiff/plugins/json.rb', line 27 def self.diff(a, b) a_value = a.value b_value = b.value a_value = JSON.parse(a_value) if a.type == :json b_value = JSON.parse(b_value) if b.type == :json ::Specdiff.diff(a_value, b_value) end |
.id ⇒ Object
6 7 8 |
# File 'lib/specdiff/plugins/json.rb', line 6 def self.id :json end |
.stringify(_diff) ⇒ Object
37 38 39 40 41 |
# File 'lib/specdiff/plugins/json.rb', line 37 def self.stringify(_diff) # since we recurse back into Specdiff, we don't need to stringify in this # plugin. the built in hash/array/text differs should do the stringification raise "#{self.class}::stringify was called, this should never happen" end |