Class: RFormat::Environment
- Inherits:
-
Object
- Object
- RFormat::Environment
- Defined in:
- lib/rformat/environment.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#custom_formatters ⇒ Object
Returns the value of attribute custom_formatters.
-
#formatters ⇒ Object
Returns the value of attribute formatters.
Instance Method Summary collapse
- #config_string ⇒ Object
- #has_custom_formats? ⇒ Boolean
- #has_rspec_config? ⇒ Boolean
-
#initialize ⇒ Environment
constructor
A new instance of Environment.
- #load_custom_formatters ⇒ Object
- #load_formatters ⇒ Object
- #rspec_config_file ⇒ Object
- #write_config ⇒ Object
Constructor Details
#initialize ⇒ Environment
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
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/rformat/environment.rb', line 6 def config @config end |
#custom_formatters ⇒ Object
Returns the value of attribute custom_formatters.
6 7 8 |
# File 'lib/rformat/environment.rb', line 6 def custom_formatters @custom_formatters end |
#formatters ⇒ Object
Returns the value of attribute formatters.
6 7 8 |
# File 'lib/rformat/environment.rb', line 6 def formatters @formatters end |
Instance Method Details
#config_string ⇒ Object
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
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
38 39 40 |
# File 'lib/rformat/environment.rb', line 38 def has_rspec_config? File.exists?(rspec_config_file) end |
#load_custom_formatters ⇒ Object
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_formatters ⇒ Object
26 27 28 |
# File 'lib/rformat/environment.rb', line 26 def load_formatters YAML.load_file(RFormat::format_file) end |
#rspec_config_file ⇒ Object
34 35 36 |
# File 'lib/rformat/environment.rb', line 34 def rspec_config_file File.join(ENV['HOME'], '.rspec') end |
#write_config ⇒ Object
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 |