class Ashikawa::Core::Index

An index on a certain collection

Attributes

id[R]

The ID of the index (includes a Collection prefix)

@return [String] @api public @example Get the id of this index

index = Ashikawa::Core::Index.new(collection, raw_index)
index.id #=> 4567
on[R]

The fields the index is defined on as symbols

@return [Array<Symbol>] @api public @example Get the fields the index is set on

index = Ashikawa::Core::Index.new(collection, raw_index)
index.fields #=> [:name]
type[R]

The type of index as a symbol

@return [Symbol] @api public @example Get the type of the index

index = Ashikawa::Core::Index.new(collection, raw_index)
index.type #=> :skiplist
unique[R]

Is the unique constraint set?

@return [Boolean] @api public @example Get the fields the index is set on

index = Ashikawa::Core::Index.new(collection, raw_index)
index.unique #=> false

Public Class Methods

new(collection, raw_index) click to toggle source

Create a new Index

@param [Collection] collection The collection the index is defined on @param [Hash] raw_index The JSON representation of the index @return [Index] @api public @example Create a new index from the raw representation

index = Ashikawa::Core::Index.new(collection, raw_index)
# File lib/ashikawa-core/index.rb, line 53
def initialize(collection, raw_index)
  @collection = collection
  @id = raw_index['id']
  @on = convert_to_symbols(raw_index['fields'])
  @type = raw_index['type'].to_sym
  @unique = raw_index['unique']
end

Public Instance Methods

delete() click to toggle source

Remove the index from the collection

@return [Hash] parsed JSON response from the server @api public @example Remove this index from the collection

index = Ashikawa::Core::Index.new(collection, raw_index)
index.delete
# File lib/ashikawa-core/index.rb, line 68
def delete
  @collection.send_request("index/#{@id}", delete: {})
end

Private Instance Methods

convert_to_symbols(arr) click to toggle source

Convert all elements of an array to symbols

@param [Array] arr @return Array @api private

# File lib/ashikawa-core/index.rb, line 79
def convert_to_symbols(arr)
  arr.map { |field| field.to_sym }
end