Sha256: cd9b9e71b5fb37eb271f8f7014bff4745591e1b81fb64e79a6e7977a676bc34d

Contents?: true

Size: 1.44 KB

Versions: 5

Compression:

Stored size: 1.44 KB

Contents

require 'singleton'
# TestDiff module
module TestDiff
  # Holds all the configuration details
  class Config
    include Singleton
    attr_accessor :working_directory, :map_subfolder,
                  :current_tracking_filename, :test_pattern

    attr_writer :test_runner, :version_control, :storage

    def initialize
      reset
    end

    def reset
      self.working_directory = '.'
      self.map_subfolder = 'test_diff_coverage'
      self.current_tracking_filename = 'sha'
      self.test_pattern = /spec.rb\z/
      @version_control = nil
      @storage = nil
      @test_runner = nil
      @logger = nil
    end

    def version_control
      @version_control ||= VersionControl::Git.new(working_directory,
                                                   File.read(current_tracking_file))
    end

    def storage
      @storage ||= Storage.new(map_folder)
    end

    def test_runner
      @test_runner ||= TestRunner::Rspec.new
    end

    def logger
      require 'logger'
      @logger ||= Logger.new($stdout)
    end

    def map_folder
      "#{working_directory}/#{map_subfolder}"
    end

    def current_tracking_file
      "#{map_folder}/#{current_tracking_filename}"
    end

    def self.method_missing(method, *args)
      if instance.respond_to?(method)
        instance.send(method, *args)
      else
        super
      end
    end

    def self.respond_to_missing?(method, *args)
      super && instance.respond_to?(method)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
test_diff-0.6.0 lib/test_diff/config.rb
test_diff-0.5.0 lib/test_diff/config.rb
test_diff-0.4.2 lib/test_diff/config.rb
test_diff-0.4.1 lib/test_diff/config.rb
test_diff-0.4.0 lib/test_diff/config.rb