Sha256: b418c783ed2f1085bc5abd40a3e980daf5fd06d56ae8cbfb56d8cf299b991028

Contents?: true

Size: 1017 Bytes

Versions: 18

Compression:

Stored size: 1017 Bytes

Contents

module Praxis
  module Handlers
    class JSON
      # Construct a JSON handler and initialize any related libraries.
      #
      # @raise [Praxis::Exceptions::InvalidConfiguration] if the handler is unsupported
      def initialize
        require 'json'
      rescue LoadError
        # Should never happen since JSON is a default gem; might as well be cautious!
        raise Praxis::Exceptions::InvalidConfiguration,
              "JSON handler depends on json ~> 1.0; please add it to your Gemfile"
      end

      # Parse a JSON document into structured data.
      #
      # @param [String] document
      # @return [Hash,Array] the structured-data representation of the document
      def parse(document)
        ::JSON.parse(document)
      end

      # Generate a pretty-printed JSON document from structured data.
      #
      # @param [Hash,Array] structured_data
      # @return [String]
      def generate(structured_data)
        ::JSON.pretty_generate(structured_data)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
praxis-2.0.pre.5 lib/praxis/handlers/json.rb
praxis-2.0.pre.4 lib/praxis/handlers/json.rb
praxis-2.0.pre.3 lib/praxis/handlers/json.rb
praxis-2.0.pre.2 lib/praxis/handlers/json.rb
praxis-2.0.pre.1 lib/praxis/handlers/json.rb
praxis-0.22.pre.2 lib/praxis/handlers/json.rb
praxis-0.22.pre.1 lib/praxis/handlers/json.rb
praxis-0.21 lib/praxis/handlers/json.rb
praxis-0.20.1 lib/praxis/handlers/json.rb
praxis-0.20.0 lib/praxis/handlers/json.rb
praxis-0.19.0 lib/praxis/handlers/json.rb
praxis-0.18.1 lib/praxis/handlers/json.rb
praxis-0.18.0 lib/praxis/handlers/json.rb
praxis-0.17.1 lib/praxis/handlers/json.rb
praxis-0.17.0 lib/praxis/handlers/json.rb
praxis-0.16.1 lib/praxis/handlers/json.rb
praxis-0.16.0 lib/praxis/handlers/json.rb
praxis-0.15.0 lib/praxis/handlers/json.rb