Sha256: 333a10bc6b80451dd423b4b4bc575ecb742689cd6cb1c441625155c352021a80

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'rom/initializer'

require 'rom/http/types'
require 'rom/http/attribute'
require 'rom/http/schema'
require 'rom/http/schema/dsl'

module ROM
  module HTTP
    # HTTP-specific relation extensions
    #
    class Relation < ROM::Relation
      include ROM::HTTP

      adapter :http

      schema_class HTTP::Schema
      schema_dsl HTTP::Schema::DSL
      schema_attr_class HTTP::Attribute

      option :output_schema, default: -> { schema.to_output_hash }

      forward :with_headers, :add_header, :with_options,
              :with_base_path, :with_path, :append_path,
              :with_request_method, :with_params, :add_params

      def primary_key
        schema.primary_key_name
      end

      def project(*names)
        with(schema: schema.project(*names.flatten))
      end

      def exclude(*names)
        with(schema: schema.exclude(*names))
      end

      def rename(mapping)
        with(schema: schema.rename(mapping))
      end

      def prefix(prefix)
        with(schema: schema.prefix(prefix))
      end

      # @see Dataset#insert
      def insert(*tuples)
        dataset.insert(*tuples.map { |t| input_schema[t] })
      end
      alias_method :<<, :insert

      # @see Dataset#update
      def update(*tuples)
        dataset.update(*tuples.map { |t| input_schema[t] })
      end

      # @see Dataset#delete
      def delete
        dataset.delete
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-http-0.8.0 lib/rom/http/relation.rb