Module: Drakkon::Settings

Defined in:
lib/drakkon/lib/settings.rb

Overview

Project Specific Config Settings

Class Method Summary collapse

Class Method Details

.app_dirObject



42
43
44
# File 'lib/drakkon/lib/settings.rb', line 42

def self.app_dir
  "#{Dir.pwd}/app"
end

.bundle_compile?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/drakkon/lib/settings.rb', line 58

def self.bundle_compile?
  config[:bundle_compile]
end

.configObject



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_defaultsObject



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_fileObject



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_dirObject



46
47
48
# File 'lib/drakkon/lib/settings.rb', line 46

def self.drakkon_dir
  "#{Dir.pwd}/app/drakkon"
end

.font_index?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/drakkon/lib/settings.rb', line 54

def self.font_index?
  config[:font_index]
end

.gemsObject



30
31
32
# File 'lib/drakkon/lib/settings.rb', line 30

def self.gems
  config[:gems]
end

.image_index?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/drakkon/lib/settings.rb', line 50

def self.image_index?
  config[:image_index]
end

.init?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


62
63
64
# File 'lib/drakkon/lib/settings.rb', line 62

def self.manifest?
  config[:manifest]
end


108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/drakkon/lib/settings.rb', line 108

def self.menu
  prompt.select('Change Settings:', filter: true) do |menu|
    menu.choice name: 'platforms', value: :platforms
    menu.choice name: 'version', value: :version
    menu.choice name: 'image_index', value: :image_index
    menu.choice name: 'font_index', value: :font_index
    menu.choice name: 'manifest', value: :manifest
    menu.choice name: 'bundle_compile', value: :bundle_compile
    menu.choice name: 'exit', value: :exit
  end
rescue TTY::Reader::InputInterrupt
  exit 0
end


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.menu_do(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

.platformsObject



38
39
40
# File 'lib/drakkon/lib/settings.rb', line 38

def self.platforms
  config[:platforms]
end

.platforms?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/drakkon/lib/settings.rb', line 34

def self.platforms?
  !config[:platforms].empty?
end

.promptObject



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

Returns:

  • (Boolean)


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

.versionObject



26
27
28
# File 'lib/drakkon/lib/settings.rb', line 26

def self.version
  config.version
end

.writeObject



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