Class: Arango::View
- Inherits:
-
Object
- Object
- Arango::View
- Includes:
- Database_Return, Helper_Error, Helper_Return
- Defined in:
- lib/View.rb
Instance Attribute Summary collapse
-
#cache_name ⇒ Object
readonly
DEFINE ===.
-
#database ⇒ Object
readonly
DEFINE ===.
-
#id ⇒ Object
Returns the value of attribute id.
-
#links ⇒ Object
readonly
DEFINE ===.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
DEFINE ===.
Class Method Summary collapse
Instance Method Summary collapse
- #addLink(collection:, analyzers: nil, fields: {}, includeAllFields: nil, trackListPositions: nil, storeValues: nil) ⇒ Object
- #body=(result) ⇒ Object (also: #assign_attributes)
- #create(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) ⇒ Object
- #destroy ⇒ Object
-
#initialize(database:, type: "arangosearch", name:, id: nil, cache_name: nil) ⇒ View
constructor
A new instance of View.
- #properties ⇒ Object
- #rename(name:) ⇒ Object
- #replaceProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) ⇒ Object
-
#retrieve ⇒ Object
COMMANDS ===.
- #to_h ⇒ Object
- #updateProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) ⇒ Object
Methods included from Database_Return
Methods included from Helper_Return
#return_delete, #return_directly?, #return_element
Methods included from Helper_Error
#satisfy_category?, #satisfy_class?, #warning_deprecated
Constructor Details
#initialize(database:, type: "arangosearch", name:, id: nil, cache_name: nil) ⇒ View
Returns a new instance of View.
29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |
Instance Attribute Details
#cache_name ⇒ Object (readonly)
DEFINE ===
44 45 46 |
# File 'lib/View.rb', line 44 def cache_name @cache_name end |
#database ⇒ Object (readonly)
DEFINE ===
44 45 46 |
# File 'lib/View.rb', line 44 def database @database end |
#id ⇒ Object
Returns the value of attribute id.
45 46 47 |
# File 'lib/View.rb', line 45 def id @id end |
#links ⇒ Object (readonly)
DEFINE ===
44 45 46 |
# File 'lib/View.rb', line 44 def links @links end |
#name ⇒ Object
Returns the value of attribute name.
45 46 47 |
# File 'lib/View.rb', line 45 def name @name end |
#type ⇒ Object
DEFINE ===
44 45 46 |
# File 'lib/View.rb', line 44 def type @type end |
Class Method Details
.new(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |
Instance Method Details
#addLink(collection:, analyzers: nil, fields: {}, includeAllFields: nil, trackListPositions: nil, storeValues: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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) ⇒ Object Also known as: assign_attributes
78 79 80 81 82 83 84 85 86 87 88 |
# 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 |
#create(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) ⇒ Object
125 126 127 |
# 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 ⇒ Object
147 148 149 |
# File 'lib/View.rb', line 147 def destroy @database.request("DELETE", "_api/view/#{@name}", key: :result) end |
#properties ⇒ Object
143 144 145 |
# File 'lib/View.rb', line 143 def properties @database.request("GET", "_api/view/#{@name}/properties") end |
#rename(name:) ⇒ Object
137 138 139 140 141 |
# 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) ⇒ Object
129 130 131 |
# 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 ⇒ Object
COMMANDS ===
93 94 95 96 97 |
# File 'lib/View.rb', line 93 def retrieve result = @database.request("GET", "_api/view/#{@name}") return result.headers[:"x-arango-async-id"] if @server.async == :store return_element(result) end |
#to_h ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# 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 |
#updateProperties(consolidationIntervalMsec: nil, threshold: nil, segmentThreshold: nil, cleanupIntervalStep: nil) ⇒ Object
133 134 135 |
# 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 |