Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/panda_motd/config.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Class Method Summary collapse
-
.component_classes ⇒ Object
The mapping of component string names to class constants.
Instance Method Summary collapse
-
#component_config(component_name) ⇒ Object
Gets the configuration for a component.
-
#components_enabled ⇒ Object
A list of enabled components’ class constants.
-
#initialize(file_path = nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(file_path = nil) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 18 |
# File 'lib/panda_motd/config.rb', line 11 def initialize(file_path = nil) @file_path = file_path || File.join(Dir.home, ".config", "panda-motd.yaml") unless File.exist?(@file_path) create_config(@file_path) puts "panda-motd created a default config file at: #{@file_path}" end load_config(@file_path) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
7 8 9 |
# File 'lib/panda_motd/config.rb', line 7 def file_path @file_path end |
Class Method Details
.component_classes ⇒ Object
The mapping of component string names to class constants.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/panda_motd/config.rb', line 37 def self.component_classes { ascii_text_art: ASCIITextArt, service_status: ServiceStatus, uptime: Uptime, ssl_certificates: SSLCertificates, filesystems: Filesystems, last_login: LastLogin, fail_2_ban: Fail2Ban, } end |
Instance Method Details
#component_config(component_name) ⇒ Object
Gets the configuration for a component.
32 33 34 |
# File 'lib/panda_motd/config.rb', line 32 def component_config(component_name) @config["components"][component_name.to_s] end |
#components_enabled ⇒ Object
A list of enabled components’ class constants.
21 22 23 24 25 26 |
# File 'lib/panda_motd/config.rb', line 21 def components_enabled # iterate config hash and grab names of enabled components enabled = @config["components"].map { |c, s| c if s["enabled"] }.compact # get the class constant enabled.map { |e| Config.component_classes[e.to_sym] } end |