Sha256: f3b63f574d62161872db9c22bb6b66e9cd857f379e44345a384383532052bc78

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 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_query_params, :add_query_params,
              :with_body_params, :add_body_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

2 entries across 2 versions & 1 rubygems

Version Path
rom-http-0.10.0 lib/rom/http/relation.rb
rom-http-0.9.0 lib/rom/http/relation.rb