Sha256: b31364335ff3d7ca8d435e6bbe64638ffcf31a55a3ad62948c14257984a78d37

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

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

10 entries across 10 versions & 1 rubygems

Version Path
rom-core-4.2.1 lib/rom/plugins/command/schema.rb
rom-core-4.2.0 lib/rom/plugins/command/schema.rb
rom-core-4.1.2 lib/rom/plugins/command/schema.rb
rom-core-4.1.1 lib/rom/plugins/command/schema.rb
rom-core-4.1.0 lib/rom/plugins/command/schema.rb
rom-core-4.0.2 lib/rom/plugins/command/schema.rb
rom-core-4.0.1 lib/rom/plugins/command/schema.rb
rom-core-4.0.0 lib/rom/plugins/command/schema.rb
rom-core-4.0.0.rc2 lib/rom/plugins/command/schema.rb
rom-core-4.0.0.rc1 lib/rom/plugins/command/schema.rb