Sha256: fdf1c1fe4df52719e3df441123fe89bfd1f6cb15b8502c0b2e09ac1e5353a300

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

module ROM
  module Plugins
    module Command
      # Command plugin which sets input processing function via relation schema
      #
      # @api private
      module Schema
        def self.included(klass)
          super
          klass.extend(ClassInterface)
        end

        # @api private
        module ClassInterface
          # Build a command and set it input to relation's input_schema
          #
          # @see Command.build
          #
          # @return [Command]
          #
          # @api public
          def build(relation, **options)
            if relation.schema? && !options.key?(:input)
              relation_input = relation.input_schema
              command_input = input

              composed_input =
                if command_input.equal?(ROM::Command.input)
                  relation_input
                else
                  -> tuple { relation_input[command_input[tuple]] }
                end

              super(relation, **options, input: composed_input)
            else
              super
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/plugins/command/schema.rb
rom-core-5.3.1 lib/rom/plugins/command/schema.rb
rom-core-5.3.0 lib/rom/plugins/command/schema.rb
rom-core-5.2.6 lib/rom/plugins/command/schema.rb
rom-core-5.2.5 lib/rom/plugins/command/schema.rb
rom-core-5.2.4 lib/rom/plugins/command/schema.rb
rom-core-5.2.3 lib/rom/plugins/command/schema.rb