Class: Triglav::Agent::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/triglav/agent/status.rb

Constant Summary

VERSION =
:v1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_uri_prefix, resource_uri) ⇒ Status

Returns a new instance of Status



11
12
13
14
15
16
# File 'lib/triglav/agent/status.rb', line 11

def initialize(resource_uri_prefix, resource_uri)
  @path = $setting.status_file
  @resource_uri_prefix = resource_uri_prefix.to_sym
  @resource_uri = resource_uri.to_sym
  @parents = [VERSION, @resource_uri_prefix, @resource_uri]
end

Instance Attribute Details

#pathObject

Returns the value of attribute path



6
7
8
# File 'lib/triglav/agent/status.rb', line 6

def path
  @path
end

#resource_uriObject (readonly)

Returns the value of attribute resource_uri



7
8
9
# File 'lib/triglav/agent/status.rb', line 7

def resource_uri
  @resource_uri
end

#resource_uri_prefixObject (readonly)

Returns the value of attribute resource_uri_prefix



7
8
9
# File 'lib/triglav/agent/status.rb', line 7

def resource_uri_prefix
  @resource_uri_prefix
end

Class Method Details

.select_resource_uri_prefixes!(resource_uri_prefixes) ⇒ Object



60
61
62
# File 'lib/triglav/agent/status.rb', line 60

def self.select_resource_uri_prefixes!(resource_uri_prefixes)
  Triglav::Agent::StorageFile.select!($setting.status_file, [VERSION], resource_uri_prefixes.map(&:to_sym))
end

.select_resource_uris!(resource_uri_prefix, resource_uris) ⇒ Object



64
65
66
# File 'lib/triglav/agent/status.rb', line 64

def self.select_resource_uris!(resource_uri_prefix, resource_uris)
  Triglav::Agent::StorageFile.select!($setting.status_file, [VERSION, resource_uri_prefix.to_sym], resource_uris.map(&:to_sym))
end

Instance Method Details

#get(*args) ⇒ Object

get(key) get(key1, key2) get() get([key1, key2])



55
56
57
58
# File 'lib/triglav/agent/status.rb', line 55

def get(*args)
  keys = (args || []).flatten
  StorageFile.get(path, [*@parents, *keys])
end

#getsetnx(*args) ⇒ Object

getsetnx(val) getsetnx(key, val) getsetnx(key1, key2, val) getsetnx(, val) getsetnx([key1, key2], val)



45
46
47
48
49
# File 'lib/triglav/agent/status.rb', line 45

def getsetnx(*args)
  val = args.pop
  keys = args.flatten
  StorageFile.getsetnx(path, [*@parents, *keys], val)
end

#set(*args) ⇒ Object

set(val) set(key, val) set(key1, key2, val) set(, val) set([key1, key2], val)



23
24
25
26
27
# File 'lib/triglav/agent/status.rb', line 23

def set(*args)
  val = args.pop
  keys = args.flatten
  StorageFile.set(path, [*@parents, *keys], val)
end

#setnx(*args) ⇒ Object

setnx(val) setnx(key, val) setnx(key1, key2, val) setnx(, val) setnx([key1, key2], val)



34
35
36
37
38
# File 'lib/triglav/agent/status.rb', line 34

def setnx(*args)
  val = args.pop
  keys = args.flatten
  StorageFile.setnx(path, [*@parents, *keys], val)
end