Sha256: 64c16b9f08ad0dfc7a161e97b222a2e3b3811fb26fd30d2b8c45d23dd6317af0

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

require_relative 'storage_file'
require 'set'

module Triglav::Agent
  class Status
    attr_accessor :path
    attr_reader :resource_uri_prefix, :resource_uri

    VERSION = :v1

    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

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

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

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

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

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

    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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
triglav-agent-1.0.0.rc1 lib/triglav/agent/status.rb