Sha256: 9dc37402e2fdebf78604b2a8794a3a04bd8382652fed6d3f571349c2a59d52dd

Contents?: true

Size: 1.53 KB

Versions: 7

Compression:

Stored size: 1.53 KB

Contents

module Koine
  class TestRunner
    class Configuration
      attr_reader :file_path

      def initialize(attributes = [])
        initialize_options(attributes.dup)
        initialize_attributes(attributes.dup)
      end

      def line
        @options[:line].to_i if line?
      end

      def line?
        @options[:line].to_s.tr('true', '').strip != ''
      end

      def all?
        @options[:all]
      end

      def last?
        @options[:last]
      end

      def config_file
        return @options[:config_file] if @options[:config_file]
        return '.test_runner.yml' if File.exist?('.test_runner.yml')
        File.expand_path('../../../config/default.yml', __dir__)
      end

      def run_options
        { file_path: file_path, line: line }
      end

      private

      def initialize_attributes(arguments)
        @file_path = arguments.reject { |arg| arg =~ /^--/ }.shift

        if require_file_name? && @file_path.nil?
          raise ArgumentError, 'file name was not given'
        end
      end

      def require_file_name?
        !last?
      end

      def initialize_options(data)
        @options = { all: false }

        data = data.select { |arg| arg =~ /^--([a-z-]+)/ }.map do |arg|
          arg.split('--').last.split('=')
        end

        data.each do |values|
          key = values.first
          value = values.length == 2 ? values.last : true
          @options[normalize_key(key)] = value
        end
      end

      def normalize_key(key)
        key.tr('-', '_').to_sym
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
koine-test_runner-0.4.0 lib/koine/test_runner/configuration.rb
koine-test_runner-0.3.0 lib/koine/test_runner/configuration.rb
koine-test_runner-0.2.4 lib/koine/test_runner/configuration.rb
koine-test_runner-0.2.3 lib/koine/test_runner/configuration.rb
koine-test_runner-0.2.2 lib/koine/test_runner/configuration.rb
koine-test_runner-0.2.1 lib/koine/test_runner/configuration.rb
koine-test_runner-0.2.0 lib/koine/test_runner/configuration.rb