Class: Splash::Backends::File

Inherits:
Object
  • Object
show all
Includes:
Config, Exiter, Helpers, Loggers
Defined in:
lib/splash/backends/file.rb

Overview

File backend definition

Constant Summary

Constants included from Loggers

Loggers::ALIAS, Loggers::LEVELS

Constants included from Constants

Constants::AUTHOR, Constants::BACKENDS_STRUCT, Constants::CONFIG_FILE, Constants::COPYRIGHT, Constants::DAEMON_LOGMON_SCHEDULING, Constants::DAEMON_METRICS_SCHEDULING, Constants::DAEMON_PID_FILE, Constants::DAEMON_PROCESS_NAME, Constants::DAEMON_PROCMON_SCHEDULING, Constants::DAEMON_STDERR_TRACE, Constants::DAEMON_STDOUT_TRACE, Constants::DEFAULT_RETENTION, Constants::EMAIL, Constants::EXECUTION_TEMPLATE, Constants::EXECUTION_TEMPLATE_TOKENS_LIST, Constants::LICENSE, Constants::LOGGERS_STRUCT, Constants::PID_PATH, Constants::PROMETHEUS_ALERTMANAGER_URL, Constants::PROMETHEUS_PUSHGATEWAY_URL, Constants::PROMETHEUS_URL, Constants::TRACE_PATH, Constants::TRANSPORTS_STRUCT, Constants::VERSION, Constants::WEBADMIN_IP, Constants::WEBADMIN_PID_FILE, Constants::WEBADMIN_PID_PATH, Constants::WEBADMIN_PORT, Constants::WEBADMIN_PROCESS_NAME, Constants::WEBADMIN_PROXY, Constants::WEBADMIN_STDERR_TRACE, Constants::WEBADMIN_STDOUT_TRACE

Constants included from Exiter

Exiter::EXIT_MAP

Instance Method Summary collapse

Methods included from Loggers

#change_logger, #get_logger, #get_session

Methods included from Config

#get_config, #rehash_config

Methods included from ConfigUtilities

#addservice, #checkconfig, #flush_backend, #setupsplash

Methods included from Helpers

#check_unicode_term, #daemonize, #format_by_extensions, #format_response, #get_processes, #group_root, #install_file, #is_root?, #make_folder, #make_link, #run_as_root, #search_file_in_gem, #user_root, #verify_file, #verify_folder, #verify_link, #verify_service

Methods included from Exiter

#splash_exit, #splash_return

Constructor Details

#initialize(store) ⇒ Splash::Backends::File

Constructor

Parameters:

  • store (Symbol)

    name in [:execution_trace] actually (see config and constants )



18
19
20
21
22
# File 'lib/splash/backends/file.rb', line 18

def initialize(store)
  @config = get_config[:backends][:stores][store]
  @path = @config[:path]
  ensure_backend
end

Instance Method Details

#del(options) ⇒ Boolean

delete a specific record

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (Boolean)

    status of the operation



56
57
58
# File 'lib/splash/backends/file.rb', line 56

def del(options)
  ::File.unlink("#{@path}/#{suffix_trace(options[:key])}") if ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
end

#exist?(options) ⇒ Boolean

verifiy a specific record existance

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (Boolean)

    presence of the record



64
65
66
# File 'lib/splash/backends/file.rb', line 64

def exist?(options)
  return ::File.exist?("#{@path}/#{suffix_trace(options[:key])}")
end

#flushObject

flush all records in backend



69
70
71
# File 'lib/splash/backends/file.rb', line 69

def flush
  Dir.glob("#{@path}/*.trace").each { |file| ::File.delete(file)}
end

#get(options) ⇒ String

return value of queried record

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

Returns:

  • (String)

    content value of record



37
38
39
# File 'lib/splash/backends/file.rb', line 37

def get(options)
  return ::File.readlines("#{@path}/#{suffix_trace(options[:key])}").join
end

#list(pattern = '*') ⇒ Array

return the list of find records in backend for a specific pattern

Parameters:

  • pattern (String) (defaults to: '*')

    shell regexp

Returns:

  • (Array)

    list of record



27
28
29
30
# File 'lib/splash/backends/file.rb', line 27

def list(pattern='*')
  pattern = suffix_trace(pattern)
  return Dir.glob("#{@path}/#{pattern}").map{|item| ::File.basename(item,".trace") }
end

#put(options) ⇒ String

defined and store value for specified key

Parameters:

  • options (Hash)

Options Hash (options):

  • :key (Symbol)

    the name of the record

  • :value (Symbol)

    the content value of the record

Returns:

  • (String)

    content value of record



46
47
48
49
50
# File 'lib/splash/backends/file.rb', line 46

def put(options)
  ::File.open("#{@path}/#{suffix_trace(options[:key])}", 'w') { |file|
    file.write options[:value]
  }
end