File: jsongem.rb

package info (click to toggle)
ruby-oembed 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 356 kB
  • sloc: ruby: 1,148; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 778 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Only allow this backend the json gem is already loaded
raise LoadError, "The json library isn't available. require 'json'" unless Object.const_defined?('JSON')

module OEmbed
  module Formatter
    module JSON
      module Backends
        module JSONGem
          extend self

          # Parses a JSON string or IO and convert it into an object.
          def decode(json)
            if json.respond_to?(:read)
              json = json.read
            end
            ::JSON.parse(json)
          end

          def decode_fail_msg
            "The version of the json library you have installed isn't parsing JSON like ruby-oembed expected."
          end

          def parse_error
            ::JSON::ParserError
          end

        end
      end
    end
  end
end