Sha256: 3b8c506ac941ec55293f6efdbed13c6a8bbb0436736f455ca9e0a15b4e21c3d3

Contents?: true

Size: 1.21 KB

Versions: 31

Compression:

Stored size: 1.21 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
        use :schema

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

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

        # @see ROM::Commands::Update#execute
        def execute(params)
          attributes = input[params]
          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

31 entries across 31 versions & 2 rubygems

Version Path
rom-core-4.2.1 lib/rom/memory/commands.rb
rom-core-4.2.0 lib/rom/memory/commands.rb
rom-core-4.1.2 lib/rom/memory/commands.rb
rom-core-4.1.1 lib/rom/memory/commands.rb
rom-core-4.1.0 lib/rom/memory/commands.rb
rom-core-4.0.2 lib/rom/memory/commands.rb
rom-core-4.0.1 lib/rom/memory/commands.rb
rom-3.3.3 lib/rom/memory/commands.rb
rom-core-4.0.0 lib/rom/memory/commands.rb
rom-3.3.2 lib/rom/memory/commands.rb
rom-core-4.0.0.rc2 lib/rom/memory/commands.rb
rom-core-4.0.0.rc1 lib/rom/memory/commands.rb
rom-core-4.0.0.beta3 lib/rom/memory/commands.rb
rom-3.3.1 lib/rom/memory/commands.rb
rom-core-4.0.0.beta2 lib/rom/memory/commands.rb
rom-3.3.0 lib/rom/memory/commands.rb
rom-core-4.0.0.beta1 lib/rom/memory/commands.rb
rom-3.2.3 lib/rom/memory/commands.rb
rom-3.2.2 lib/rom/memory/commands.rb
rom-3.2.1 lib/rom/memory/commands.rb