class RFormat::Environment

Attributes

config[RW]
custom_formatters[RW]
formatters[RW]

Public Class Methods

new() click to toggle source
# File lib/rformat/environment.rb, line 8
def initialize
  @config = {
    color: true,
    formats: {
      default: 'default'
    }
  }
  load_custom_formatters
end

Public Instance Methods

config_string() click to toggle source
# File lib/rformat/environment.rb, line 48
def config_string
  color_string = @config[:color] ? '--color' : ''
  formats_string = @config[:formats].values.map { |f| "--format #{f}" }.join(" ")
  "#{color_string} #{formats_string}"
end
has_custom_formats?() click to toggle source
# File lib/rformat/environment.rb, line 18
def has_custom_formats?
  File.exists?(RFormat::rformat_env_file)
end
has_rspec_config?() click to toggle source
# File lib/rformat/environment.rb, line 38
def has_rspec_config?
  File.exists?(rspec_config_file)
end
load_custom_formatters() click to toggle source
# File lib/rformat/environment.rb, line 30
def load_custom_formatters
  @custom_formatters ||= has_custom_formats? ? YAML.load_file(RFormat::rformat_env_file) : {}
end
load_formatters() click to toggle source
# File lib/rformat/environment.rb, line 26
def load_formatters
  YAML.load_file(RFormat::format_file)
end
rspec_config_file() click to toggle source
# File lib/rformat/environment.rb, line 34
def rspec_config_file
  File.join(ENV['HOME'], '.rspec')
end
write_config() click to toggle source
# File lib/rformat/environment.rb, line 42
def write_config
  File.open(rspec_config_file, 'w+') do |f|
    f << config_string
  end
end