Module: GreenHat::Settings
- Defined in:
- lib/greenhat/settings.rb
Overview
Helper for all things user environment / settings / history
Class Method Summary collapse
- .assume_json? ⇒ Boolean
- .cmd_add(line) ⇒ Object
- .cmd_file ⇒ Object
-
.cmd_history ⇒ Object
———————————- Command History.
- .cmd_history_clean ⇒ Object
- .cmd_history_clear ⇒ Object
-
.color? ⇒ Boolean
Allow for future disabling of color output.
-
.default_log_flags(flags, skip_flags) ⇒ Object
Set any Log Arguments that weren’t set otherwise | Conditional assign applied on bool rubocop:disable Style/GuardClause.
- .dir ⇒ Object
-
.history_file ⇒ Object
File Load History.
- .settings ⇒ Object
- .settings_file ⇒ Object
-
.settings_load ⇒ Object
Load User Settings and drop them into settings.
-
.start ⇒ Object
rubocop:enable Style/GuardClause.
Class Method Details
.assume_json? ⇒ Boolean
18 19 20 |
# File 'lib/greenhat/settings.rb', line 18 def self.assume_json? settings.assume_json end |
.cmd_add(line) ⇒ Object
88 89 90 |
# File 'lib/greenhat/settings.rb', line 88 def self.cmd_add(line) File.write(cmd_file, line, File.size(cmd_file), mode: 'a') end |
.cmd_file ⇒ Object
76 77 78 |
# File 'lib/greenhat/settings.rb', line 76 def self.cmd_file "#{dir}/cmd_history" end |
.cmd_history ⇒ Object
Command History
72 73 74 |
# File 'lib/greenhat/settings.rb', line 72 def self.cmd_history "#{dir}/cmd_history" end |
.cmd_history_clean ⇒ Object
80 81 82 |
# File 'lib/greenhat/settings.rb', line 80 def self.cmd_history_clean File.read(cmd_file).split("\n") end |
.cmd_history_clear ⇒ Object
84 85 86 |
# File 'lib/greenhat/settings.rb', line 84 def self.cmd_history_clear File.write(cmd_file, "\n") end |
.color? ⇒ Boolean
Allow for future disabling of color output
23 24 25 |
# File 'lib/greenhat/settings.rb', line 23 def self.color? settings.color end |
.default_log_flags(flags, skip_flags) ⇒ Object
Set any Log Arguments that weren’t set otherwise | Conditional assign applied on bool rubocop:disable Style/GuardClause
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/greenhat/settings.rb', line 42 def self.default_log_flags(flags, skip_flags) flags[:round] = settings.round if !(skip_flags.include?(:round) || flags.key?(:round)) && settings.round flags[:page] = settings.page if !(skip_flags.include?(:page) || flags.key?(:page)) && settings.page flags[:truncate] = settings.truncate unless skip_flags.include?(:truncate) || flags.key?(:truncate) # Fuzzy File Match unless skip_flags.include?(:fuzzy_file_match) || flags.key?(:fuzzy_file_match) flags[:fuzzy_file_match] = settings.fuzzy_file_match end end |
.dir ⇒ Object
66 67 68 |
# File 'lib/greenhat/settings.rb', line 66 def self.dir "#{ENV['HOME']}/.greenhat" end |
.history_file ⇒ Object
File Load History
95 96 97 |
# File 'lib/greenhat/settings.rb', line 95 def self.history_file "#{dir}/file_history" end |
.settings ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/greenhat/settings.rb', line 5 def self.settings @settings ||= { history: [], assume_json: true, fuzzy_file_match: true, # round: [2], # page: [:true] Automatic, truncate: TTY::Screen.width * 4, color: true } end |
.settings_file ⇒ Object
36 37 38 |
# File 'lib/greenhat/settings.rb', line 36 def self.settings_file "#{dir}/settings.json" end |
.settings_load ⇒ Object
Load User Settings and drop them into settings
28 29 30 31 32 33 34 |
# File 'lib/greenhat/settings.rb', line 28 def self.settings_load return true unless File.exist?(settings_file) Oj.load(File.read(settings_file)).each do |key, value| settings[key] = value end end |
.start ⇒ Object
rubocop:enable Style/GuardClause
56 57 58 59 60 61 62 63 64 |
# File 'lib/greenhat/settings.rb', line 56 def self.start Dir.mkdir dir unless Dir.exist? dir # Load User Settings settings_load # CMD History Loading / Tracking File.write(cmd_file, "\n") unless File.exist? cmd_file end |