Class: Arango::Index
- Inherits:
-
Object
- Object
- Arango::Index
- Includes:
- Helper::DatabaseAssignment, Helper::Satisfaction
- Defined in:
- lib/arango/index.rb
Overview
Arango Index
Instance Attribute Summary collapse
-
#cache_name ⇒ Object
DEFINE ===.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#deduplicate ⇒ Object
DEFINE ===.
-
#fields ⇒ Object
DEFINE ===.
-
#geo_json ⇒ Object
DEFINE ===.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#is_newly_created ⇒ Object
readonly
Returns the value of attribute is_newly_created.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#min_length ⇒ Object
DEFINE ===.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#sparse ⇒ Object
DEFINE ===.
-
#type ⇒ Object
Returns the value of attribute type.
-
#unique ⇒ Object
DEFINE ===.
Class Method Summary collapse
-
.get(collection:, id:) ⇒ Arango::Result
get collection for index.
-
.list(collection:) ⇒ Array of Arango::Index
list indexes defined for collection.
Instance Method Summary collapse
-
#assign_attributes(result) ⇒ Object
set index attributes from hash.
-
#create ⇒ Object
create Index in database.
-
#delete ⇒ Object
delete datbase index.
-
#initialize(collection:, fields:, cache_name: nil, deduplicate: nil, geo_json: nil, min_length: nil, sparse: nil, type: "hash", unique: nil) ⇒ Index
constructor
create new Arango::Index instance.
-
#to_h ⇒ Hash
convert index to hash.
-
#to_s ⇒ Object
String representation.
Methods included from Helper::Satisfaction
#satisfy_category?, #satisfy_class?, #satisfy_class_or_string?, #satisfy_module?, #satisfy_module_or_nil?, #satisfy_module_or_string?, #warning_deprecated
Constructor Details
#initialize(collection:, fields:, cache_name: nil, deduplicate: nil, geo_json: nil, min_length: nil, sparse: nil, type: "hash", unique: nil) ⇒ Index
create new Arango::Index instance
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/arango/index.rb', line 34 def initialize(collection:, fields:, cache_name: nil, deduplicate: nil, geo_json: nil, min_length: nil, sparse: nil, type: "hash", unique: nil) @collection = collection assign_database(@collection.database) unless cache_name.nil? @cache_name = cache_name @server.cache.save(:index, cache_name, self) end body = {} body[:type] ||= type body[:sparse] ||= sparse body[:unique] ||= unique body[:fields] ||= fields.is_a?(String) ? [fields] : fields body[:deduplicate] ||= deduplicate body[:geo_json] ||= geo_json body[:min_length] ||= min_length assign_attributes(body) end |
Instance Attribute Details
#cache_name ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def cache_name @cache_name end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def collection @collection end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def database @database end |
#deduplicate ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def deduplicate @deduplicate end |
#fields ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def fields @fields end |
#geo_json ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def geo_json @geo_json end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def id @id end |
#is_newly_created ⇒ Object (readonly)
Returns the value of attribute is_newly_created.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def is_newly_created @is_newly_created end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def key @key end |
#min_length ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def min_length @min_length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def name @name end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def server @server end |
#sparse ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def sparse @sparse end |
#type ⇒ Object
Returns the value of attribute type.
57 58 59 |
# File 'lib/arango/index.rb', line 57 def type @type end |
#unique ⇒ Object
DEFINE ===
56 57 58 |
# File 'lib/arango/index.rb', line 56 def unique @unique end |
Class Method Details
.get(collection:, id:) ⇒ Arango::Result
get collection for index
28 29 30 31 |
# File 'lib/arango/index.rb', line 28 def self.get collection:, id: c, i = id.split '/' # Requests would convert / to %2F Arango::Requests::Index::Get.execute(server: collection.database.server, args: {collection: c, id: i}) end |
.list(collection:) ⇒ Array of Arango::Index
list indexes defined for collection
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/arango/index.rb', line 11 def self.list(collection:) params = { collection: collection.name } result = Arango::Requests::Index::ListAll.execute(server: collection.database.server, params: params) if result.response_code == 200 return result.indexes.map do |v| self.new collection: collection, fields: v[:fields], type: v[:type], deduplicate: v[:deduplicate], geo_json: v[:geo_json], min_length: v[:min_length], sparse: v[:sparse], unique: v[:unique] end end # FIXME - raise error nil end |
Instance Method Details
#assign_attributes(result) ⇒ Object
set index attributes from hash
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arango/index.rb', line 69 def assign_attributes(result) @id = result[:id] || @id @name = result[:name] || @name @key = @id&.split("/")&.dig(1) @type = assign_type(result[:type] || @type) @unique = result[:unique] || @unique @fields = result[:fields] || @fields @sparse = result[:sparse] || @sparse @geo_json = result[:geoJson] || @geo_json @min_length = result[:minLength] || @min_length @deduplicate = result[:deduplicate] || @deduplicate @is_newly_created = result[:is_newly_created] @estimates = result[:estimates] || @estimates end |
#create ⇒ Object
create Index in database
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/arango/index.rb', line 109 def create body = { fields: @fields, type: @type } params = { collection: @collection.name } case @type.to_sym when :hash body[:deduplicate] = @deduplicate if @deduplicate body[:sparse] = @sparse if @sparse body[:unique] = @unique if @unique when :fulltext body[:min_length] = @min_length if @min_length when :general body[:deduplicate] = @deduplicate if @deduplicate body[:name] = @name if @name body[:sparse] = @sparse if @sparse body[:unique] = @unique if @unique when :geo body[:geo_jso] = @geo_json if @geo_json when :persistent body[:sparse] = @sparse if @sparse body[:unique] = @unique if @unique when :skiplist body[:deduplicate] = @deduplicate if @deduplicate body[:sparse] = @sparse if @sparse body[:unique] = @unique if @unique when :ttl body[:expire_after] = @expire_after if @expire_after else raise "Unknown index type #{@type.to_sym}" end result = Arango::Requests::Index::Create.execute(server: @database.server, params: params, body: body) assign_attributes result self end |
#delete ⇒ Object
delete datbase index
152 153 154 155 |
# File 'lib/arango/index.rb', line 152 def delete c, i = @id.split '/' # Requests would convert / to %2F Arango::Requests::Index::Delete.execute(server: @database.server, args: { collection: c, id: i}) end |
#to_h ⇒ Hash
convert index to hash
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/arango/index.rb', line 88 def to_h { key: @key, id: @id, name: @name, body: @body, type: @type, sparse: @sparse, unique: @unique, fields: @fields, idCache: @idCache, geoJson: @geo_json, minLength: @min_length, deduplicate: @deduplicate, collection: @collection.name }.delete_if{|k,v| v.nil?} end |
#to_s ⇒ Object
String representation
147 148 149 |
# File 'lib/arango/index.rb', line 147 def to_s "Index(#{@id}:#{@type.to_sym}-#{@fields})" end |