class Arango::View
Attributes
id[RW]
name[RW]
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
# File lib/View.rb, line 9 def self.new(*args) hash = args[0] super unless hash.is_a?(Hash) database = hash[:database] if database.is_a?(Arango::Database) && database.server.active_cache && !hash[:id].nil? cache_name = "#{database.name}/#{hash[:id]}" cached = database.server.cache.cache.dig(:view, cache_name) if cached.nil? hash[:cache_name] = cache_name return super else body = {} [:type, :name].each{|k| body[k] ||= hash[k]} cached.assign_attributes(body) return cached end end super end
new(database:, type: "arangosearch", name:, id: nil, cache_name: nil)
click to toggle source
# File lib/View.rb, line 29 def initialize(database:, type: "arangosearch", name:, id: nil, cache_name: nil) assign_database(database) unless cache_name.nil? @cache_name = cache_name @server.cache.save(:view, cache_name, self) end satisfy_category?(type, ["arangosearch"]) @type = type @name = name @links = {} @id = id end
Public Instance Methods
addLink(collection:, analyzers: nil, fields: {}, includeAllFields: nil, trackListPositions: nil, storeValues: nil)
click to toggle source
# File lib/View.rb, line 53 def addLink(collection:, analyzers: nil, fields: {}, includeAllFields: nil, trackListPositions: nil, storeValues: nil) satisfy_class?(collection, [Arango::Collection, String]) collection_name = collection.is_a?(String) ? collection : collection.name satisfy_category?(storeValues, ["none", "id", nil]) @links[collection_name] = { analyzers: analyzers, fields: fields, includeAllFields: includeAllFields, trackListPositions: trackListPositions, storeValues: storeValues } @links[collection_name].delete_if{|k,v| v.nil?} end
body=(result)
click to toggle source
# File lib/View.rb, line 78 def body=(result) @body = result @id = result[:id] || @id @type = assign_type(result[:type] || @type) @links = result[:links] || @links @name = result[:name] || name if @server.active_cache && @cache_name.nil? @cache_name = "#{@database.name}/#{@id}" @server.cache.save(:task, @cache_name, self) end end
Also aliased as: assign_attributes
create(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
click to toggle source
# File lib/View.rb, line 125 def create(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) manage_properties("POST", "_api/view", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep) end
destroy()
click to toggle source
# File lib/View.rb, line 147 def destroy @database.request("DELETE", "_api/view/#{@name}", key: :result) end
properties()
click to toggle source
# File lib/View.rb, line 143 def properties @database.request("GET", "_api/view/#{@name}/properties") end
rename(name: body = {name: name})
click to toggle source
# File lib/View.rb, line 137 def rename name: body = {name: name} result = @database.request("PUT", "_api/view/#{@name}/rename", body: body) return_element(result) end
replaceProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
click to toggle source
# File lib/View.rb, line 129 def replaceProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) manage_properties("PUT", "_api/view/#{@name}/properties", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep) end
retrieve()
click to toggle source
to_h()
click to toggle source
# File lib/View.rb, line 67 def to_h { "name": @name, "id": @id, "type": @type, "links": @links, "cache_name": @cache_name, "database": @database.name }.delete_if{|k,v| v.nil?} end
type=(type)
click to toggle source
# File lib/View.rb, line 47 def type=(type) satisfy_category?(type, ["arangosearch"]) @type = type end
Also aliased as: assign_type
updateProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
click to toggle source
# File lib/View.rb, line 133 def updateProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) manage_properties("PATCH", "_api/view/#{@name}/properties", consolidationIntervalMsec: consolidationIntervalMsec, threshold: threshold, segmentThreshold: segmentThreshold, cleanupIntervalStep: cleanupIntervalStep) end
Private Instance Methods
manage_properties(method, url, consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil)
click to toggle source
# File lib/View.rb, line 99 def manage_properties(method, url, consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) body = { properties: { links: @links.empty? ? nil : @links, consolidationIntervalMsec: consolidationIntervalMsec, consolidationPolicy: { threshold: threshold, segmentThreshold: segmentThreshold }, cleanupIntervalStep: cleanupIntervalStep } } if method == "POST" body[:type] = @type body[:name] = @name end body[:properties][:consolidationPolicy].delete_if{|k,v| v.nil?} body[:properties].delete(:consolidationPolicy) if body[:properties][:consolidationPolicy].empty? body[:properties].delete_if{|k,v| v.nil?} body.delete(:properties) if body[:properties].empty? body.delete_if{|k,v| v.nil?} result = @database.request(method, url, body: body) return_element(result) end