Sha256: c7af190cc0dc59d307a375c6b30ce7779899cb3e942c0a18bcdeb0580dc7c643

Contents?: true

Size: 1.11 KB

Versions: 22

Compression:

Stored size: 1.11 KB

Contents

module OEmbed
  module Formatter
    # Handles parsing JSON values using the best available backend.
    module JSON
      # A Array of all available backends, listed in order of preference.
      DECODERS = %w(ActiveSupportJSON JSONGem Yaml)
      
      class << self
        include ::OEmbed::Formatter::Base
        
        # Returns the current JSON backend.
        def backend
          set_default_backend unless defined?(@backend)
          raise OEmbed::FormatNotSupported, :json unless defined?(@backend)
          @backend
        end

        def set_default_backend
          DECODERS.find do |name|
            begin
              self.backend = name
              true
            rescue LoadError
              # Try next decoder.
              false
            end
          end
        end
        
        private
        
        def backend_path
          'json/backends'
        end
        
        def test_value
          <<-JSON
{"version":"1.0", "string":"test", "int":42,"html":"<i>Cool's</i>\\n the \\"word\\"\\u0021"}
          JSON
        end
        
      end # self
      
    end # JSON
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ruby-oembed-0.16.1 lib/oembed/formatter/json.rb
ruby-oembed-0.16.0 lib/oembed/formatter/json.rb
ruby-oembed-0.15.0 lib/oembed/formatter/json.rb
ruby-oembed-0.14.1 lib/oembed/formatter/json.rb
ruby-oembed-0.14.0 lib/oembed/formatter/json.rb
ruby-oembed-0.13.1 lib/oembed/formatter/json.rb
ruby-oembed-0.13.0 lib/oembed/formatter/json.rb
ruby-oembed-0.12.0 lib/oembed/formatter/json.rb
ruby-oembed-0.11.0 lib/oembed/formatter/json.rb
ruby-oembed-0.10.1 lib/oembed/formatter/json.rb
ruby-oembed-0.10.0 lib/oembed/formatter/json.rb
ruby-oembed-0.9.0 lib/oembed/formatter/json.rb
ruby-oembed-0.8.14 lib/oembed/formatter/json.rb
ruby-oembed-0.8.13 lib/oembed/formatter/json.rb
ruby-oembed-0.8.12 lib/oembed/formatter/json.rb
ruby-oembed-0.8.11 lib/oembed/formatter/json.rb
ruby-oembed-0.8.10 lib/oembed/formatter/json.rb
ruby-oembed-0.8.9 lib/oembed/formatter/json.rb
ruby-oembed-0.8.8 lib/oembed/formatter/json.rb
ruby-oembed-0.8.7 lib/oembed/formatter/json.rb