Class: RFormat::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/rformat/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



8
9
10
11
12
13
14
15
16
# File 'lib/rformat/environment.rb', line 8

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/rformat/environment.rb', line 6

def config
  @config
end

#custom_formattersObject

Returns the value of attribute custom_formatters.



6
7
8
# File 'lib/rformat/environment.rb', line 6

def custom_formatters
  @custom_formatters
end

#formattersObject

Returns the value of attribute formatters.



6
7
8
# File 'lib/rformat/environment.rb', line 6

def formatters
  @formatters
end

Instance Method Details

#config_stringObject



48
49
50
51
52
# 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?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rformat/environment.rb', line 18

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

#has_rspec_config?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rformat/environment.rb', line 38

def has_rspec_config?
  File.exists?(rspec_config_file)
end

#load_custom_formattersObject



30
31
32
# 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_formattersObject



26
27
28
# File 'lib/rformat/environment.rb', line 26

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

#rspec_config_fileObject



34
35
36
# File 'lib/rformat/environment.rb', line 34

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

#write_configObject



42
43
44
45
46
# File 'lib/rformat/environment.rb', line 42

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