Sha256: 58b347b6d481680ae1ab14c54a0bdd43223d2aa08105fdffc1477b08741e144b

Contents?: true

Size: 941 Bytes

Versions: 5

Compression:

Stored size: 941 Bytes

Contents

require 'rom/commands'

module ROM
  module Elasticsearch
    # ElasticSearch relation commands
    #
    # @api public
    class Commands
      # Create command
      #
      # @api public
      class Create < ROM::Commands::Create
        # @api private
        def execute(attributes)
          tuple = input[attributes]

          result =
            if _id
              dataset.params(id: tuple.fetch(_id)).put(tuple)
            else
              dataset.put(tuple)
            end
          [relation.get(result['_id']).one]
        end

        private

        # @api private
        def dataset
          relation.dataset
        end

        def _id
          relation.schema.primary_key_name
        end
      end

      # Delete command
      #
      # @api public
      class Delete < ROM::Commands::Delete
        # @api private
        def execute
          relation.dataset.delete
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rom-elasticsearch-0.3.0 lib/rom/elasticsearch/commands.rb
rom-elasticsearch-0.2.1 lib/rom/elasticsearch/commands.rb
rom-elasticsearch-0.2.0 lib/rom/elasticsearch/commands.rb
rom-elasticsearch-0.1.1 lib/rom/elasticsearch/commands.rb
rom-elasticsearch-0.1.0 lib/rom/elasticsearch/commands.rb