class ExistClient::Config

Constants

DEFAULT_CUTOFF_HOUR
DEFAULT_DATA_PATH

Public Class Methods

config_file() click to toggle source
# File lib/exist_client/config.rb, line 29
def config_file
  @config_file ||= data_path.join("config.yml")
end
cutoff_hour() click to toggle source
# File lib/exist_client/config.rb, line 33
def cutoff_hour
  config_values.fetch("cutoff_hour", DEFAULT_CUTOFF_HOUR)
end
data_path() click to toggle source
# File lib/exist_client/config.rb, line 25
def data_path
  @data_path ||= Pathname.new(DEFAULT_DATA_PATH).expand_path
end
data_path_for(reporter) click to toggle source
# File lib/exist_client/config.rb, line 37
def data_path_for(reporter)
  data_path.join(reporter.metric_name)
end
enabled_reporters() click to toggle source
# File lib/exist_client/config.rb, line 49
def enabled_reporters
  @enabled_reporters ||= plugins.keys.map { |reporter| constantize(reporter) }
end
last_report_date_file() click to toggle source
# File lib/exist_client/config.rb, line 45
def last_report_date_file
  data_path.join("last_report_date")
end
plugin_for(reporter) click to toggle source
# File lib/exist_client/config.rb, line 41
def plugin_for(reporter)
  @plugins.fetch(reporter.metric_name)
end
set_data_path(relative_data_path) click to toggle source
# File lib/exist_client/config.rb, line 21
def set_data_path(relative_data_path)
  @data_path = Pathname.new(relative_data_path).expand_path
end
setup(relative_data_path = DEFAULT_DATA_PATH) click to toggle source
# File lib/exist_client/config.rb, line 9
def setup(relative_data_path = DEFAULT_DATA_PATH)
  set_data_path(relative_data_path)

  puts "  Creating directory at #{data_path}"
  data_path.mkpath

  puts "  Creating config file at #{config_file}"
  config_file.write("")

  last_report_date_file.write("2000-01-01")
end

Private Class Methods

config_values() click to toggle source
# File lib/exist_client/config.rb, line 55
def config_values
  @config_values ||= YAML.load_file(config_file)
end
constantize(str) click to toggle source
# File lib/exist_client/config.rb, line 73
def constantize(str)
  class_name = str.split("_").map(&:capitalize).join
  ExistClient.const_get(class_name)
end
load_plugins() click to toggle source
# File lib/exist_client/config.rb, line 63
def load_plugins
  plugin_map = config_values.fetch("plugins").map do |reporter, plugin|
    require "exist_client/#{plugin}"

    [reporter, constantize(plugin)]
  end

  plugin_map.to_h
end
plugins() click to toggle source
# File lib/exist_client/config.rb, line 59
def plugins
  @plugins ||= load_plugins
end