class Arango::Index
Attributes
collection[R]
database[R]
server[R]
type[R]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/Index.rb, line 9 def self.new(*args) hash = args[0] super unless hash.is_a?(Hash) collection = hash[:collection] if collection.is_a?(Arango::Collection) && collection.database.server.active_cache && !hash[:id].nil? cache_name = "#{collection.database.name}/#{collection.name}/#{hash[:id]}" cached = collection.database.server.cache.cache.dig(:index, cache_name) if cached.nil? hash[:cache_name] = cache_name return super else body = hash[:body] || {} [:type, :sparse, :unique, :fields, :deduplicate, :geoJson, :minLength].each{|k| body[k] ||= hash[k]} cached.assign_attributes(body) return cached end end super end
new(collection:, body: {}, id: nil, type: "hash", unique: nil, fields:, sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil, cache_name: nil)
click to toggle source
# File lib/Index.rb, line 30 def initialize(collection:, body: {}, id: nil, type: "hash", unique: nil, fields:, sparse: nil, geoJson: nil, minLength: nil, deduplicate: nil, cache_name: nil) assign_collection(collection) unless cache_name.nil? @cache_name = cache_name @server.cache.save(:index, cache_name, self) end body[:type] ||= type body[:id] ||= id body[:sparse] ||= sparse body[:unique] ||= unique body[:fields] ||= fields.is_a?(String) ? [fields] : fields body[:deduplicate] ||= deduplicate body[:geoJson] ||= geoJson body[:minLength] ||= minLength assign_attributes(body) end
Public Instance Methods
body=(result)
click to toggle source
# File lib/Index.rb, line 62 def body=(result) @body = result @id = result[:id] || @id @key = @id&.split("/")&.dig(1) @type = assign_type(result[:type] || @type) @unique = result[:unique] || @unique @fields = result[:fields] || @fields @sparse = result[:sparse] || @sparse @geoJson = result[:geoJson] || @geoJson @minLength = result[:minLength] || @minLength @deduplicate = result[:deduplicate] || @deduplicate if @server.active_cache && @cache_name.nil? @cache_name = "#{@database.name}/#{@collection.name}/#{@id}" @server.cache.save(:index, @cache_name, self) end end
Also aliased as: assign_attributes
create()
click to toggle source
# File lib/Index.rb, line 106 def create body = { "fields": @fields, "unique": @unique, "type": @type, "id": @id, "geoJson": @geoJson, "minLength": @minLength, "deduplicate": @deduplicate } query = { "collection": @collection.name } result = @database.request("POST", "_api/index", body: body, query: query) return_element(result) end
destroy()
click to toggle source
# File lib/Index.rb, line 121 def destroy result = @database.request("DELETE", "_api/index/#{@id}") return_delete(result) end
retrieve()
click to toggle source
to_h()
click to toggle source
DEFINE ===¶ ↑
# File lib/Index.rb, line 82 def to_h { "key": @key, "id": @id, "body": @body, "type": @type, "sparse": @sparse, "unique": @unique, "fields": @fields, "idCache": @idCache, "geoJson": @geoJson, "minLength": @minLength, "deduplicate": @deduplicate, "collection": @collection.name }.delete_if{|k,v| v.nil?} end
type=(type)
click to toggle source
# File lib/Index.rb, line 56 def type=(type) satisfy_category?(type, ["hash", "skiplist", "persistent", "geo", "fulltext", "primary"]) @type = type end
Also aliased as: assign_type