Sha256: e1e29ad2008eb97d7709cb870dfc4161fbfa337f7dc29f8549003498a5e5fb81

Contents?: true

Size: 611 Bytes

Versions: 4

Compression:

Stored size: 611 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/
        MultiJson.load( req.body.read )
      else
        {}
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cuba-api-0.6.0 lib/cuba_api/input_filter.rb
cuba-api-0.5.1 lib/cuba_api/input_filter.rb
cuba-api-0.5.0 lib/cuba_api/input_filter.rb
cuba-api-0.4.0 lib/cuba_api/input_filter.rb