Sha256: f2c2002a0cd1d9eb5b8455ec9bcfecc5b742ac0a4f43929a6b21da55f39ba2a3

Contents?: true

Size: 889 Bytes

Versions: 4

Compression:

Stored size: 889 Bytes

Contents

require 'deas/view_handler'
require 'much-plugin'

module Deas::Json

  module ViewHandler
    include MuchPlugin

    DEF_STATUS  = 200.freeze
    DEF_HEADERS = {}.freeze
    DEF_BODY    = '{}'.freeze

    plugin_included do
      include Deas::ViewHandler
      include InstanceMethods

      before_init{ content_type('.json', 'charset' => 'utf-8') }
    end

    module InstanceMethods

      private

      # Some http clients will error when trying to parse an empty body when the
      # content type is 'json'.  This will default the body to a string that
      # can be parsed to an empty json object
      def halt(*args)
        super(
          args.first.instance_of?(::Fixnum) ? args.shift : DEF_STATUS,
          args.first.kind_of?(::Hash) ? args.shift : DEF_HEADERS,
          args.first.respond_to?(:each) ? args.shift : DEF_BODY
        )
      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
deas-json-0.3.3 lib/deas-json/view_handler.rb
deas-json-0.3.2 lib/deas-json/view_handler.rb
deas-json-0.3.1 lib/deas-json/view_handler.rb
deas-json-0.3.0 lib/deas-json/view_handler.rb