<commit_before>require 'dotenv'
require 'hashie'

module Pagerduty
  module CLT
    class Config
      include PathHelper

      DEFAULT_CONFIG_FILE = File.join(ENV['HOME'], '.pagerduty_env')

      def initialize(config_file = DEFAULT_CONFIG_FILE)
        @config_file = config_file
        Dotenv.load(config_file)
      end

      def settings
        @settings ||= Hashie::Mash.new(hash)
      end

      def me
        @me ||= begin
          path = users_path(settings.user_id)
          User.new($connection.get(path).user)
        end
      end

      private

        attr_reader :config_file

        def hash
          {
            account: {
              name:    ENV['PAGERDUTY_ACCOUNT_NAME']    || fail("Missing ENV['PAGERDUTY_ACCOUNT_NAME'], add to #{config_file}"),
              token:   ENV['PAGERDUTY_ACCOUNT_TOKEN']   || fail("Missing ENV['PAGERDUTY_ACCOUNT_TOKEN'], add to #{config_file}")
            },
            user_id:   ENV['PAGERDUTY_USER_ID']         || fail("Missing ENV['PAGERDUTY_USER_ID'], add to #{config_file}")
          }
        end<commit_msg>Use new User.find in Config<commit_after>require 'dotenv'
require 'hashie'

module Pagerduty
  module CLT
    class Config
      include PathHelper

      DEFAULT_CONFIG_FILE = File.join(ENV['HOME'], '.pagerduty_env')

      def initialize(config_file = DEFAULT_CONFIG_FILE)
        @config_file = config_file
        Dotenv.load(config_file)
      end

      def settings
        @settings ||= Hashie::Mash.new(hash)
      end

      def me
        @me ||= User.find(settings.user_id)
      end

      private

        attr_reader :config_file

        def hash
          {
            account: {
              name:    ENV['PAGERDUTY_ACCOUNT_NAME']    || fail("Missing ENV['PAGERDUTY_ACCOUNT_NAME'], add to #{config_file}"),
              token:   ENV['PAGERDUTY_ACCOUNT_TOKEN']   || fail("Missing ENV['PAGERDUTY_ACCOUNT_TOKEN'], add to #{config_file}")
            },
            user_id:   ENV['PAGERDUTY_USER_ID']         || fail("Missing ENV['PAGERDUTY_USER_ID'], add to #{config_file}")
          }
        end
{'fraction_non_alphanumeric': 0.10794103661436044, 'fraction_numerical': 0.0, 'mean_word_length': 2.2319508448540706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3800002', 'n_tokens_mistral': 693, 'n_tokens_neox': 674, 'n_words': 127}