Module: Drakkon::Settings
- Defined in:
- lib/drakkon/lib/settings.rb
Overview
Project Specific Config Settings
Class Method Summary collapse
- .app_dir ⇒ Object
- .bundle_compile? ⇒ Boolean
- .config ⇒ Object
- .config_defaults ⇒ Object
- .config_file ⇒ Object
- .delete(key) ⇒ Object
- .drakkon_dir ⇒ Object
- .font_index? ⇒ Boolean
- .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 |
.bundle_compile? ⇒ Boolean
58 59 60 |
# File 'lib/drakkon/lib/settings.rb', line 58 def self.bundle_compile? config[:bundle_compile] end |
.config ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/drakkon/lib/settings.rb', line 81 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_defaults end @config end |
.config_defaults ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/drakkon/lib/settings.rb', line 70 def self.config_defaults # Defaults @config[:platforms] ||= [] @config[:version] ||= Hub.version_latest @config[:image_index] = true if @config[:image_index].nil? @config[:manifest] = true if @config[:manifest].nil? @config[:bundle_compile] = true if @config[:bundle_compile].nil? @config[:font_index] = true if @config[:font_index].nil? @config[:gems] ||= {} end |
.config_file ⇒ Object
66 67 68 |
# File 'lib/drakkon/lib/settings.rb', line 66 def self.config_file "#{Dir.pwd}/.drakkon" end |
.delete(key) ⇒ Object
98 99 100 101 |
# File 'lib/drakkon/lib/settings.rb', line 98 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 |
.font_index? ⇒ Boolean
54 55 56 |
# File 'lib/drakkon/lib/settings.rb', line 54 def self.font_index? config[:font_index] 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
62 63 64 |
# File 'lib/drakkon/lib/settings.rb', line 62 def self.manifest? config[:manifest] end |
.menu ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/drakkon/lib/settings.rb', line 108 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: 'font_index', value: :font_index .choice name: 'manifest', value: :manifest .choice name: 'bundle_compile', value: :bundle_compile .choice name: 'exit', value: :exit end rescue TTY::Reader::InputInterrupt exit 0 end |
.menu_do(arg) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/drakkon/lib/settings.rb', line 122 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 :bundle_compile Settings.update(:bundle_compile, prompt.yes?("Create Bundle / Compile Gems? (Enabled: #{config[:bundle_compile]})")) when :font_index Settings.update(:font_index, prompt.yes?("Index Fonts? (Enabled: #{config[:font_index]})")) 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 false if init? LogBot.warn('Setup', "Drakkon not configured. Run #{'init'.pastel(:green)} first") exit 1 end |
.update(key, value) ⇒ Object
93 94 95 96 |
# File 'lib/drakkon/lib/settings.rb', line 93 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
103 104 105 106 |
# File 'lib/drakkon/lib/settings.rb', line 103 def self.write # LogBot.debug('Settings', "Writing Config: #{config_file}") File.write(config_file, JSON.pretty_generate(config)) end |