Module: Papertrail::CliHelpers
- Included in:
- Cli, CliAddGroup, CliAddSystem, CliJoinGroup, CliLeaveGroup, CliRemoveSystem
- Defined in:
- lib/papertrail/cli_helpers.rb
Instance Method Summary collapse
- #find_configfile ⇒ Object
- #load_configfile(file_path) ⇒ Object
- #output_http_error(e) ⇒ Object
- #parse_time(tstring) ⇒ Object
- #set_min_max_time!(opts, q_opts) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Instance Method Details
permalink #find_configfile ⇒ Object
[View source]
3 4 5 6 7 8 9 10 11 |
# File 'lib/papertrail/cli_helpers.rb', line 3 def find_configfile if File.exists?(path = File.('.papertrail.yml')) return path end if File.exists?(path = File.('~/.papertrail.yml')) return path end rescue ArgumentError end |
permalink #load_configfile(file_path) ⇒ Object
[View source]
13 14 15 |
# File 'lib/papertrail/cli_helpers.rb', line 13 def load_configfile(file_path) symbolize_keys(YAML.load_file(file_path)) end |
permalink #output_http_error(e) ⇒ Object
[View source]
36 37 38 39 40 41 42 |
# File 'lib/papertrail/cli_helpers.rb', line 36 def output_http_error(e) if e.response && e.response.body puts "Error: #{e.response.body}\n\n" end puts e end |
permalink #parse_time(tstring) ⇒ Object
[View source]
31 32 33 34 |
# File 'lib/papertrail/cli_helpers.rb', line 31 def parse_time(tstring) Chronic.parse(tstring) || raise(ArgumentError, "Could not parse time string '#{tstring}'") end |
permalink #set_min_max_time!(opts, q_opts) ⇒ Object
[View source]
26 27 28 29 |
# File 'lib/papertrail/cli_helpers.rb', line 26 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 |
permalink #symbolize_keys(hash) ⇒ Object
[View source]
17 18 19 20 21 22 23 24 |
# File 'lib/papertrail/cli_helpers.rb', line 17 def symbolize_keys(hash) new_hash = {} hash.each do |(key, value)| new_hash[(key.to_sym rescue key) || key] = value end new_hash end |