Module: Papertrail::CliHelpers

Included in:
Cli, CliAddGroup, CliAddSystem, CliJoinGroup, CliRemoveSystem
Defined in:
lib/papertrail/cli_helpers.rb

Instance Method Summary collapse

Instance Method Details

#find_configfileObject



3
4
5
6
7
8
9
10
# File 'lib/papertrail/cli_helpers.rb', line 3

def find_configfile
  if File.exists?(path = File.expand_path('.papertrail.yml'))
    return path
  end
  if File.exists?(path = File.expand_path('~/.papertrail.yml'))
    return path
  end
end

#load_configfile(file_path) ⇒ Object



12
13
14
# File 'lib/papertrail/cli_helpers.rb', line 12

def load_configfile(file_path)
  symbolize_keys(YAML.load_file(file_path))
end

#parse_time(tstring) ⇒ Object



30
31
32
33
# File 'lib/papertrail/cli_helpers.rb', line 30

def parse_time(tstring)
  Chronic.parse(tstring) ||
    raise(ArgumentError, "Could not parse time string '#{tstring}'")
end

#set_min_max_time!(opts, q_opts) ⇒ Object



25
26
27
28
# File 'lib/papertrail/cli_helpers.rb', line 25

def set_min_max_time!(opts, q_opts)
  q_opts[:min_time] = parse_time(opts[:min_time]).to_i if opts[:min_time]
  q_opts[:max_time] = parse_time(opts[:max_time]).to_i if opts[:max_time]
end

#symbolize_keys(hash) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/papertrail/cli_helpers.rb', line 16

def symbolize_keys(hash)
  new_hash = {}
  hash.each do |(key, value)|
    new_hash[(key.to_sym rescue key) || key] = value
  end

  new_hash
end