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

.configObject



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_defaultsObject



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_fileObject



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_dirObject



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

def self.drakkon_dir
  "#{Dir.pwd}/app/drakkon"
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)


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

def self.manifest?
  config[:manifest]
end


100
101
102
103
104
105
106
107
108
109
110
# File 'lib/drakkon/lib/settings.rb', line 100

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


112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/drakkon/lib/settings.rb', line 112

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 :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 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

.versionObject



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

def self.version
  config.version
end

.writeObject



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