Class: Howzit::Config
- Inherits:
-
Object
- Object
- Howzit::Config
- 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, stack: 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#editor ⇒ Object
Initiate the editor for the config.
-
#initialize ⇒ Config
constructor
Initialize a config object.
-
#should_ignore(filename) ⇒ Object
Test if a file should be ignored based on YAML file.
-
#template_folder ⇒ String
Find the template folder.
-
#update_config_option(options) ⇒ Object
Update a config option and resave config file.
-
#update_editor ⇒ Object
Update editor config.
-
#write_config(config) ⇒ Object
Write a config to a file.
-
#write_theme(config) ⇒ Object
Write a theme to a file.
Constructor Details
#initialize ⇒ Config
Initialize a config object
71 72 73 74 75 76 77 78 |
# File 'lib/howzit/config.rb', line 71 def initialize @initializing = true begin ensure @initializing = false end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/howzit/config.rb', line 6 def @options end |
Instance Method Details
#editor ⇒ Object
Initiate the editor for the config
151 152 153 |
# File 'lib/howzit/config.rb', line 151 def editor edit_config end |
#should_ignore(filename) ⇒ Object
Test if a file should be ignored based on YAML file
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/howzit/config.rb', line 103 def should_ignore(filename) # Prevent recursion: if we're already loading ignore patterns, skip the check return false if defined?(@loading_ignore_patterns) && @loading_ignore_patterns # Don't check the ignore file itself - do this before any file operations begin ignore_file_path = ignore_file return false if filename == ignore_file_path || File.(filename) == File.(ignore_file_path) rescue StandardError # If ignore_file access fails, skip the check to prevent recursion return false end return false unless File.exist?(ignore_file_path) begin @loading_ignore_patterns = true @ignore_patterns ||= YAML.load(Util.read_file(ignore_file_path)) ensure @loading_ignore_patterns = false end return false unless @ignore_patterns.is_a?(Array) ignore = false @ignore_patterns.each do |pat| if filename =~ /#{pat}/ ignore = true break end end ignore end |
#template_folder ⇒ String
Find the template folder
144 145 146 |
# File 'lib/howzit/config.rb', line 144 def template_folder File.join(config_dir, 'templates') end |
#update_config_option(options) ⇒ Object
Update a config option and resave config file
185 186 187 188 189 190 |
# File 'lib/howzit/config.rb', line 185 def update_config_option() .each do |key, value| Howzit.[key] = value end write_config(Howzit.) end |
#update_editor ⇒ Object
Update editor config
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/howzit/config.rb', line 156 def update_editor begin puts 'No $EDITOR defined, no value in config' rescue Errno::EPIPE # Pipe closed, ignore end editor = Prompt.read_editor if editor.nil? begin puts 'Cancelled, no editor stored.' rescue Errno::EPIPE # Pipe closed, ignore end Process.exit 1 end update_config_option({ config_editor: editor, editor: editor }) begin puts "Default editor set to #{editor}, modify in config file" rescue Errno::EPIPE # Pipe closed, ignore end editor end |
#write_config(config) ⇒ Object
Write a config to a file
85 86 87 |
# File 'lib/howzit/config.rb', line 85 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
94 95 96 |
# File 'lib/howzit/config.rb', line 94 def write_theme(config) File.open(theme_file, 'w') { |f| f.puts config.to_yaml } end |