Sha256: c65ce1da9aca5a6253c9ddffae61db497e7d6bb8bdf505904af5821f5f2ef81a

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

require 'rom/commands'

module ROM
  module Memory
    # Memory adapter commands namespace
    #
    # @api public
    module Commands
      # In-memory create command
      #
      # @api public
      class Create < ROM::Commands::Create
        adapter :memory

        # @see ROM::Commands::Create#execute
        def execute(tuples)
          Array([tuples]).flatten.map do |tuple|
            attributes = input[tuple]
            validator.call(attributes)
            relation.insert(attributes.to_h)
            attributes
          end.to_a
        end
      end

      # In-memory update command
      #
      # @api public
      class Update < ROM::Commands::Update
        adapter :memory

        # @see ROM::Commands::Update#execute
        def execute(params)
          attributes = input[params]
          validator.call(attributes)
          relation.map { |tuple| tuple.update(attributes.to_h) }
        end
      end

      # In-memory delete command
      #
      # @api public
      class Delete < ROM::Commands::Delete
        adapter :memory

        # @see ROM::Commands::Delete#execute
        def execute
          relation.to_a.map do |tuple|
            source.delete(tuple)
            tuple
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-0.9.1 lib/rom/memory/commands.rb
rom-0.9.0 lib/rom/memory/commands.rb
rom-0.9.0.rc1 lib/rom/memory/commands.rb
rom-0.9.0.beta1 lib/rom/memory/commands.rb
rom-0.8.1 lib/rom/memory/commands.rb
rom-0.8.0 lib/rom/memory/commands.rb