Class: RubyEdit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_edit/configuration.rb

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



7
8
9
10
# File 'lib/ruby_edit/configuration.rb', line 7

def initialize
  @config = TTY::Config.new
  @config.read("#{RubyEdit::CONFIGURATION_LOCATION}.yml")
end

Instance Method Details

#editorObject



12
13
14
# File 'lib/ruby_edit/configuration.rb', line 12

def editor
  @config.fetch(:editor) || 'vim'
end

#editor=(editor) ⇒ Object



16
17
18
19
# File 'lib/ruby_edit/configuration.rb', line 16

def editor=(editor)
  @config.set(:editor, value: editor)
  write
end

#grep_optionsObject



21
22
23
24
25
26
# File 'lib/ruby_edit/configuration.rb', line 21

def grep_options
  options = @config.fetch(:grep_options) || 'ir'
  # The n option is needed for edited changes to be applied, so it needs to be added here
  # automatically
  "#{options}n"
end

#grep_options=(grep_options) ⇒ Object



28
29
30
31
32
# File 'lib/ruby_edit/configuration.rb', line 28

def grep_options=(grep_options)
  # All occurences of n are removed, as n is autamatically added when the options are fetched.
  @config.set(:grep_options, value: grep_options.gsub('n', ''))
  write
end

#reset_defaultsObject



34
35
36
37
38
# File 'lib/ruby_edit/configuration.rb', line 34

def reset_defaults
  @config.set(:editor, value: 'vim')
  @config.set(:grep_options, value: 'ir')
  write
end