Sha256: 2ea0ad6b8d4e6f22a3fa527b89ee555e62cd4e57448ef58562cfb542c7aaece8

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module ROM
  module Commands
    # Delete command
    #
    # This command removes tuples from its target relation
    #
    # @abstract
    class Delete < AbstractCommand
      attr_reader :target

      def initialize(relation, options)
        super
        @target = options[:target] || relation
      end

      # @see AbstractCommand#call
      def call(*args)
        assert_tuple_count
        super
      end

      # Execute the command
      #
      # @abstract
      #
      # @return [Array] an array with removed tuples
      #
      # @api private
      def execute
        raise(
          NotImplementedError,
          "#{self.class}##{__method__} must be implemented"
        )
      end

      # Create a new delete command scoped to specific relation and execute it
      #
      # @api private
      def new(*args, &block)
        new_options = options.merge(target: relation.public_send(*args, &block))
        command = self.class.new(relation, new_options)
        command.call
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-0.5.0 lib/rom/commands/delete.rb