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
DEFAULT_COLORS =
[
  [:black,              30],
  [:red,                31],
  [:green,              32],
  [:yellow,             33],
  [:blue,               34],
  [:magenta,            35],
  [:purple,             35],
  [:cyan,               36],
  [:white,              37],
  [:bgblack,            40],
  [:bgred,              41],
  [:bggreen,            42],
  [:bgyellow,           43],
  [:bgblue,             44],
  [:bgmagenta,          45],
  [:bgpurple,           45],
  [:bgcyan,             46],
  [:bgwhite,            47],
  [:boldblack,          90],
  [:boldred,            91],
  [:boldgreen,          92],
  [:boldyellow,         93],
  [:boldblue,           94],
  [:boldmagenta,        95],
  [:boldpurple,         95],
  [:boldcyan,           96],
  [:boldwhite,          97],
  [:boldbgblack,       100],
  [:boldbgred,         101],
  [:boldbggreen,       102],
  [:boldbgyellow,      103],
  [:boldbgblue,        104],
  [:boldbgmagenta,     105],
  [:boldbgpurple,      105],
  [:boldbgcyan,        106],
  [:boldbgwhite,       107]
].to_h.deep_freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Initialize a config object



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

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



124
125
126
# File 'lib/howzit/config.rb', line 124

def editor
  edit_config
end

#should_ignore(filename) ⇒ Object

Test if a file should be ignored based on YAML file



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/howzit/config.rb', line 95

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



117
118
119
# File 'lib/howzit/config.rb', line 117

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

#write_config(config) ⇒ Object

Write a config to a file



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

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

#write_theme(config) ⇒ Object

Write a theme to a file



86
87
88
# File 'lib/howzit/config.rb', line 86

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