Module: Drakkon::Settings

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

Overview

Project Specific Config Settings

Class Method Summary collapse

Class Method Details

.app_dirObject



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

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

.bundle_compile?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/drakkon/lib/settings.rb', line 73

def self.bundle_compile?
  config[:bundle_compile]
end

.check_version!Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/drakkon/lib/settings.rb', line 22

def self.check_version!
  return if Hub.version?(version)

  LogBot.warn('Setup', "DragonRuby #{version} not installed.")
  LogBot.warn('Setup', 'Select a version to use:')

  Version.set

  exit(1) unless Hub.version?(version)
end

.configObject



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/drakkon/lib/settings.rb', line 121

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
    write
  end

  @config
end

.config_defaultsObject



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

def self.config_defaults
  # Defaults
  @config[:platforms] ||= []
  @config[:version] ||= Hub.version_latest
  @config[:image_index] = enable_image_index?
  @config[:manifest] = true if @config[:manifest].nil?
  @config[:bundle_compile] = true if @config[:bundle_compile].nil?
  @config[:manifest_compile] = false if @config[:manifest_compile].nil?
  @config[:font_index] = true if @config[:font_index].nil?
  @config[:sound_index] = true if @config[:sound_index].nil?
  @config[:gems] ||= {}
end

.config_fileObject



85
86
87
# File 'lib/drakkon/lib/settings.rb', line 85

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

.delete(key) ⇒ Object



139
140
141
142
# File 'lib/drakkon/lib/settings.rb', line 139

def self.delete(key)
  config.delete key
  write
end

.drakkon_dirObject



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

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

.enable_image_index?Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
# File 'lib/drakkon/lib/settings.rb', line 99

def self.enable_image_index?
  return false unless image_magick_installed?

  # TODO: Determine if this should default to True?
  return true if config[:image_index].nil?

  config[:image_index]
end

.font_index?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/drakkon/lib/settings.rb', line 65

def self.font_index?
  config[:font_index]
end

.gemsObject



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

def self.gems
  config[:gems]
end

.image_index?Boolean

Returns:

  • (Boolean)


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

def self.image_index?
  config[:image_index]
end

.image_magick_installed?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
95
96
97
# File 'lib/drakkon/lib/settings.rb', line 89

def self.image_magick_installed?
  # Use Minimagick's utilities to check if ImageMagick is installed
  # https://github.com/minimagick/minimagick/pull/193
  !MiniMagick::Utilities.which('convert').nil?

  # MiniMagick::Image.open('metadata/icon.png')
rescue MiniMagick::Invalid, Errno::ENOENT
  false
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)


81
82
83
# File 'lib/drakkon/lib/settings.rb', line 81

def self.manifest?
  config[:manifest]
end

.manifest_compile?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/drakkon/lib/settings.rb', line 77

def self.manifest_compile?
  config[:manifest_compile]
end


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/drakkon/lib/settings.rb', line 149

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: 'sound_index', value: :sound_index
    menu.choice name: 'manifest', value: :manifest
    menu.choice name: 'manifest_compile', value: :manifest_compile
    menu.choice name: 'bundle_compile', value: :bundle_compile
    menu.choice name: 'exit', value: :exit
  end
rescue TTY::Reader::InputInterrupt
  exit 0
end


165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/drakkon/lib/settings.rb', line 165

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 :manifest_compile
    Settings.update(:manifest_compile,
                    prompt.yes?("Bundle Manifest On Build? (Enabled: #{config[:manifest_compile]})"))
  when :font_index
    Settings.update(:font_index, prompt.yes?("Index Fonts? (Enabled: #{config[:font_index]})"))
  when :sound_index
    Settings.update(:font_index, prompt.yes?("Index Sounds? (Enabled: #{config[:sound_index]})"))
  when :exit
    exit 0
  end
end

.platformsObject



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

def self.platforms
  config[:platforms]
end

.platforms?Boolean

Returns:

  • (Boolean)


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

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

.promptObject



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

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

.sound_index?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/drakkon/lib/settings.rb', line 69

def self.sound_index?
  config[:sound_index]
end

.update(key, value) ⇒ Object



134
135
136
137
# File 'lib/drakkon/lib/settings.rb', line 134

def self.update(key, value)
  config[key] = value
  write
end

.versionObject



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

def self.version
  config.version
end

.writeObject



144
145
146
147
# File 'lib/drakkon/lib/settings.rb', line 144

def self.write
  # LogBot.debug('Settings', "Writing Config: #{config_file}")
  File.write(config_file, JSON.pretty_generate(config))
end