Class: Howzit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/howzit/config.rb

Overview

Config Class

Constant Summary collapse

DEFAULTS =

Configuration defaults

{
  color: true,
  config_editor: ENV['EDITOR'] || nil,
  editor: ENV['EDITOR'] || nil,
  header_format: 'border',
  highlight: true,
  highlighter: 'auto',
  include_upstream: false,
  log_level: 1, # 0: debug, 1: info, 2: warn, 3: error
  matching: 'partial', # exact, partial, fuzzy, beginswith
  multiple_matches: 'choose',
  output_title: false,
  pager: 'auto',
  paginate: true,
  show_all_code: false,
  show_all_on_error: false,
  wrap: 0
}.deep_freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Initialize a config object



29
30
31
# File 'lib/howzit/config.rb', line 29

def initialize
  load_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/howzit/config.rb', line 4

def options
  @options
end

Instance Method Details

#editorObject

Initiate the editor for the config



76
77
78
# File 'lib/howzit/config.rb', line 76

def editor
  edit_config
end

#should_ignore(filename) ⇒ Object

Test if a file should be ignored based on YAML file

Parameters:

  • filename

    The filename to test



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/howzit/config.rb', line 47

def should_ignore(filename)
  return false unless File.exist?(ignore_file)

  @ignore_patterns ||= YAML.safe_load(Util.read_file(ignore_file))

  ignore = false

  @ignore_patterns.each do |pat|
    if filename =~ /#{pat}/
      ignore = true
      break
    end
  end

  ignore
end

#template_folderString

Find the template folder

Returns:

  • (String)

    path to template folder



69
70
71
# File 'lib/howzit/config.rb', line 69

def template_folder
  File.join(config_dir, 'templates')
end

#write_config(config) ⇒ Object

Write a config to a file

Parameters:

  • config

    The configuration



38
39
40
# File 'lib/howzit/config.rb', line 38

def write_config(config)
  File.open(config_file, 'w') { |f| f.puts config.to_yaml }
end