Sha256: e4c490dbaa2ae7354173cf98580c3babd0121f99695e38d4134bdc16830223a9

Contents?: true

Size: 650 Bytes

Versions: 3

Compression:

Stored size: 650 Bytes

Contents

require 'ixtlan/babel/factory'
require 'multi_json'
module CubaApi
  module InputFilter

    module ClassMethods
      def factory
        @_factory ||= Ixtlan::Babel::Factory.new
      end
    end

    def req_filter( model = nil, context = nil )
      @_filter ||=
        begin
          filter = self.class.factory.new_filter( model ).use( context )
          filter.filter_it( parse_request_body )
        end
    end

    protected

    def parse_request_body
      if env[ 'CONTENT_TYPE' ] =~ /^application\/json/
        body = req.body.read
        body.empty? ? {} : MultiJson.load( body )
      else
        {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cuba-api-0.6.3 lib/cuba_api/input_filter.rb
cuba-api-0.6.2 lib/cuba_api/input_filter.rb
cuba-api-0.6.1 lib/cuba_api/input_filter.rb