Sha256: 1abbd87e931ca020c748562d3c314cfa3ef60f5948ea740a59f97f238eb32aa1

Contents?: true

Size: 982 Bytes

Versions: 6

Compression:

Stored size: 982 Bytes

Contents

module Alf
  module Rest
    class Request < Rack::Request

      def initialize(env, heading)
        super(env)
        @heading  = Heading.coerce(heading)
      end
      attr_reader :heading

      def to_relation
        relation = Relation.coerce(each.to_a)
        commons  = heading.to_attr_list & relation.heading.to_attr_list
        relation.project(commons).coerce(heading.project(commons))
      end

      def to_tuple
        to_relation.tuple_extract
      end

    private

      def each(&bl)
        return to_enum unless block_given?
        if form_data?
          yield(Support.symbolize_keys(self.POST))
        else
          Alf::Reader.by_mime_type(media_type, body_io).each(&bl)
        end
      end

      def body_io
        case body
        when IO, StringIO then body
        else
          body.rewind if body.respond_to?(:rewind)
          StringIO.new(body.read)
        end
      end

    end # class Request
  end # module Rest
end # module Alf

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alf-rest-0.17.1 lib/alf/rest/request.rb
alf-rest-0.16.3 lib/alf/rest/request.rb
alf-rest-0.16.2 lib/alf/rest/request.rb
alf-rest-0.16.1 lib/alf/rest/request.rb
alf-rest-0.16.0 lib/alf/rest/request.rb
alf-rest-0.14.0 lib/alf/rest/request.rb