<commit_before>class Settings
  module DataSource
    class File
      dependency :logger, Telemetry::Logger

      attr_reader :source

      def initialize(source)
        @source = source
      end

      def self.build(source=nil)
        logger = Telemetry::Logger.get self

        logger.trace "Building"

        new(source).tap do |instance|
          Telemetry::Logger.configure instance
          logger.debug "Built"
        end
      end

      def canonical
        dirpath = nil
        filepath = nil

        unless source.nil?
          if ::File.extname(source) == ""
            dirpath = Pathname.new(source)
            filepath = Pathname.new(Defaults.filename)
          end
        end

        if source.nil?
          dirpath = Pathname.new(Directory::Defaults.pathname)
          filepath = Pathname.new(Defaults.filename)
        else
          if ::File.dirname(source) == "."
            dirpath = Pathname.new(Directory::Defaults.pathname)
            filepath = Pathname.new(source)
          end
        end

        (dirpath + filepath).to_s
      end

      module Defaults
        def self.logger
          @logger ||= ::Telemetry::Logger.get self
        end

        def self.filename
          default_file = 'settings.json' # .tap
          logger.debug "Using the default settings file name (#{default_file})"
          default_file<commit_msg>File and directory detection code is clearer<commit_after>class Settings
  module DataSource
    class File
      dependency :logger, Telemetry::Logger

      attr_reader :source

      def initialize(source)
        @source = source
      end

      def self.build(source=nil)
        logger = Telemetry::Logger.get self

        logger.trace "Building"

        new(source).tap do |instance|
          Telemetry::Logger.configure instance
          logger.debug "Built"
        end
      end

      def canonical
        dirpath = nil
        filepath = nil

        unless source.nil?
          unless file?(source)
            dirpath = Pathname.new(source)
            filepath = Pathname.new(Defaults.filename)
          end
        end

        if source.nil?
          dirpath = Pathname.new(Directory::Defaults.pathname)
          filepath = Pathname.new(Defaults.filename)
        else
          unless dir?(source)
            dirpath = Pathname.new(Directory::Defaults.pathname)
            filepath = Pathname.new(source)
          end
        end

        (dirpath + filepath).to_s
      end

      def file?(filepath)
        ::File.extname(filepath) != ""
      end

      def dir?(dirpath)
        ::File.dirname(dirpath) != "."
      end

      module Defaults
        def self.logger
          @logger ||= ::Telemetry::Logger.get self
        end

        def self.filename
          default_file = 'settings.json' # .tap
          logger.debug "Using the default settings file name (#{default_file})"
          default_file
{'fraction_non_alphanumeric': 0.08603618982587914, 'fraction_numerical': 0.0, 'mean_word_length': 1.771996215704825, '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': '3808548', 'n_tokens_mistral': 802, 'n_tokens_neox': 764, 'n_words': 189}