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