Module: OEmbed::Formatter::JSON

Extended by:
Base
Defined in:
lib/oembed/formatter/json.rb,
lib/oembed/formatter/json/backends/yaml.rb,
lib/oembed/formatter/json/backends/jsongem.rb,
lib/oembed/formatter/json/backends/activesupportjson.rb

Overview

Handles parsing JSON values using the best available backend.

Defined Under Namespace

Modules: Backends

Constant Summary collapse

DECODERS =

A Array of all available backends, listed in order of preference.

%w(ActiveSupportJSON JSONGem Yaml)

Class Method Summary collapse

Methods included from Base

backend=, decode, reset_backend, supported?, with_backend

Class Method Details

.backendObject

Returns the current JSON backend.



12
13
14
15
16
# File 'lib/oembed/formatter/json.rb', line 12

def backend
  set_default_backend unless defined?(@backend)
  raise OEmbed::FormatNotSupported, :json unless defined?(@backend)
  @backend
end

.set_default_backendObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/oembed/formatter/json.rb', line 18

def set_default_backend
  DECODERS.find do |name|
    begin
      self.backend = name
      true
    rescue LoadError
      # Try next decoder.
      false
    end
  end
end