Class: Ashikawa::Core::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/ashikawa-core/index.rb

Overview

An index on a certain collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, raw_index) ⇒ Index

Create a new Index

Examples:

Create a new index from the raw representation

index = Ashikawa::Core::Index.new(collection, raw_index)

Parameters:

  • collection (Collection)

    The collection the index is defined on

  • raw_index (Hash)

    The JSON representation of the index


54
55
56
57
58
59
60
# File 'lib/ashikawa-core/index.rb', line 54

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

Instance Attribute Details

#idString (readonly)

The ID of the index (includes a Collection prefix)

Examples:

Get the id of this index

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

Returns:

  • (String)

44
45
46
# File 'lib/ashikawa-core/index.rb', line 44

def id
  @id
end

#onArray<Symbol> (readonly)

The fields the index is defined on as symbols

Examples:

Get the fields the index is set on

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

Returns:

  • (Array<Symbol>)

17
18
19
# File 'lib/ashikawa-core/index.rb', line 17

def on
  @on
end

#typeSymbol (readonly)

The type of index as a symbol

Examples:

Get the type of the index

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

Returns:

  • (Symbol)

26
27
28
# File 'lib/ashikawa-core/index.rb', line 26

def type
  @type
end

#uniqueBoolean (readonly)

Is the unique constraint set?

Examples:

Get the fields the index is set on

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

Returns:

  • (Boolean)

35
36
37
# File 'lib/ashikawa-core/index.rb', line 35

def unique
  @unique
end

Instance Method Details

#deleteHash

Remove the index from the collection

Examples:

Remove this index from the collection

index = Ashikawa::Core::Index.new(collection, raw_index)
index.delete

Returns:

  • (Hash)

    parsed JSON response from the server


69
70
71
# File 'lib/ashikawa-core/index.rb', line 69

def delete
  @collection.send_request("index/#{@id}", delete: {})
end