Sha256: b83cafae38a690a892146700acb78b856e2326811efc0f3cd523e044bb4d6274

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

require 'rformat'

module RFormat
  class Environment

    attr_accessor :config, :formatters, :custom_formatters

    def initialize
      @config = {
        color: true,
        formats: {
          default: 'default'
        }
      }
      load_custom_formatters
    end

    def has_custom_formats?
      File.exists?(RFormat::rformat_env_file)
    end

    def formatters
      load_formatters.merge custom_formatters
    end

    def load_formatters
      YAML.load_file(RFormat::format_file)
    end

    def load_custom_formatters
      @custom_formatters ||= has_custom_formats? ? YAML.load_file(RFormat::rformat_env_file) : {}
    end

    def rspec_config_file
      File.join(ENV['HOME'], '.rspec')
    end

    def has_rspec_config?
      File.exists?(rspec_config_file)
    end

    def write_config
      File.open(rspec_config_file, 'w+') do |f|
        f << config_string
      end
    end

    def config_string
      color_string = @config[:color] ? '--color' : ''
      formats_string = @config[:formats].values.map { |f| "--format #{f}" }.join(" ")
      "#{color_string} #{formats_string}"
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rformat-0.1.2 lib/rformat/environment.rb
rformat-0.1.1 lib/rformat/environment.rb
rformat-0.1.0 lib/rformat/environment.rb