Sha256: 571b93b814107bed624d589650d08da627d8d9bd2d4e5842008291432acd7037

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 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 options.key?(:input) || !relation.schema?
              super
            else
              default_input = options.fetch(:input, input)

              input_handler =
                if default_input != Hash
                  -> tuple { relation.input_schema[input[tuple]] }
                else
                  relation.input_schema
                end

              super(relation, options.merge(input: input_handler))
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-core-5.1.2 lib/rom/plugins/command/schema.rb
rom-core-5.1.1 lib/rom/plugins/command/schema.rb
rom-core-5.1.0 lib/rom/plugins/command/schema.rb
rom-core-5.0.2 lib/rom/plugins/command/schema.rb
rom-core-5.0.1 lib/rom/plugins/command/schema.rb
rom-core-5.0.0 lib/rom/plugins/command/schema.rb