Module: Drakkon::Settings
- Defined in:
- lib/drakkon/lib/settings.rb
Overview
Project Specific Config Settings
Class Method Summary collapse
- .app_dir ⇒ Object
- .config ⇒ Object
- .config_defaults ⇒ Object
- .config_file ⇒ Object
- .delete(key) ⇒ Object
- .drakkon_dir ⇒ Object
- .gems ⇒ Object
- .image_index? ⇒ Boolean
- .init? ⇒ Boolean
- .manifest? ⇒ Boolean
- .menu ⇒ Object
- .menu_do(arg) ⇒ Object
- .platforms ⇒ Object
- .platforms? ⇒ Boolean
- .prompt ⇒ Object
-
.ready? ⇒ Boolean
Helper to exit if project isn’t ready for drakkon usage.
- .update(key, value) ⇒ Object
- .version ⇒ Object
- .write ⇒ Object
Class Method Details
.app_dir ⇒ Object
42 43 44 |
# File 'lib/drakkon/lib/settings.rb', line 42 def self.app_dir "#{Dir.pwd}/app" end |
.config ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/drakkon/lib/settings.rb', line 71 def self.config # Write Default File.write(config_file, JSON.pretty_generate({})) unless File.exist?(config_file) if @config.nil? @config ||= JSON.parse(File.read(config_file), { symbolize_names: true }) # @config ||= Oj.load File.read(config_file) config_defaults end @config end |
.config_defaults ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/drakkon/lib/settings.rb', line 62 def self.config_defaults # Defaults @config[:platforms] ||= [] @config[:version] ||= Hub.version_latest @config[:image_index] ||= true @config[:manifest] ||= true @config[:gems] ||= {} end |
.config_file ⇒ Object
58 59 60 |
# File 'lib/drakkon/lib/settings.rb', line 58 def self.config_file "#{Dir.pwd}/.drakkon" end |
.delete(key) ⇒ Object
89 90 91 92 |
# File 'lib/drakkon/lib/settings.rb', line 89 def self.delete(key) config.delete key write end |
.drakkon_dir ⇒ Object
46 47 48 |
# File 'lib/drakkon/lib/settings.rb', line 46 def self.drakkon_dir "#{Dir.pwd}/app/drakkon" end |
.gems ⇒ Object
30 31 32 |
# File 'lib/drakkon/lib/settings.rb', line 30 def self.gems config[:gems] end |
.image_index? ⇒ Boolean
50 51 52 |
# File 'lib/drakkon/lib/settings.rb', line 50 def self.image_index? config[:image_index] end |
.init? ⇒ Boolean
4 5 6 7 8 9 10 11 |
# File 'lib/drakkon/lib/settings.rb', line 4 def self.init? if File.directory?(config_file) LogBot.fatal('Settings', "Conflicting Config / Directory #{config_file}") exit 0 end File.exist?(config_file) end |
.manifest? ⇒ Boolean
54 55 56 |
# File 'lib/drakkon/lib/settings.rb', line 54 def self.manifest? config[:manifest] end |
.menu ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/drakkon/lib/settings.rb', line 100 def self. prompt.select('Change Settings:', filter: true) do || .choice name: 'platforms', value: :platforms .choice name: 'version', value: :version .choice name: 'image_index', value: :image_index .choice name: 'manifest', value: :manifest .choice name: 'exit', value: :exit end rescue TTY::Reader::InputInterrupt exit 0 end |
.menu_do(arg) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/drakkon/lib/settings.rb', line 112 def self.(arg) case arg when :platforms Settings.update(:platforms, Build.platform_setup) when :version Version.set when :image_index Settings.update(:image_index, prompt.yes?("Index Images? (Enabled: #{image_index?})")) when :manifest Settings.update(:image_index, prompt.yes?("Write Manifest? (Enabled: #{manifest?})")) when :exit exit 0 end end |
.platforms ⇒ Object
38 39 40 |
# File 'lib/drakkon/lib/settings.rb', line 38 def self.platforms config[:platforms] end |
.platforms? ⇒ Boolean
34 35 36 |
# File 'lib/drakkon/lib/settings.rb', line 34 def self.platforms? !config[:platforms].empty? end |
.prompt ⇒ Object
22 23 24 |
# File 'lib/drakkon/lib/settings.rb', line 22 def self.prompt TTY::Prompt.new(active_color: :cyan, interrupt: :exit) end |
.ready? ⇒ Boolean
Helper to exit if project isn’t ready for drakkon usage
14 15 16 17 18 19 20 |
# File 'lib/drakkon/lib/settings.rb', line 14 def self.ready? return if init? LogBot.warn('Setup', "Drakkon not configured. Run #{'init'.pastel(:green)} first") exit 1 end |
.update(key, value) ⇒ Object
84 85 86 87 |
# File 'lib/drakkon/lib/settings.rb', line 84 def self.update(key, value) config[key] = value write end |
.version ⇒ Object
26 27 28 |
# File 'lib/drakkon/lib/settings.rb', line 26 def self.version config.version end |
.write ⇒ Object
94 95 96 97 98 |
# File 'lib/drakkon/lib/settings.rb', line 94 def self.write # LogBot.debug('Settings', "Writing Config: #{config_file}") File.write(config_file, JSON.pretty_generate(config)) # File.write(config_file, Oj.dump(config)) end |