Sha256: d3bca0d4f913a7015e5d5fd44e1d8064215548a1293576c4a335668962b4819a

Contents?: true

Size: 889 Bytes

Versions: 5

Compression:

Stored size: 889 Bytes

Contents

module Papertrail
  module CliHelpers
    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

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

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

      new_hash
    end

    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

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

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
papertrail-0.9.9 lib/papertrail/cli_helpers.rb
papertrail-0.9.8 lib/papertrail/cli_helpers.rb
papertrail-0.9.7 lib/papertrail/cli_helpers.rb
papertrail-0.9.6 lib/papertrail/cli_helpers.rb
papertrail-0.9.5 lib/papertrail/cli_helpers.rb