Class: VScripts::Config
- Inherits:
-
Object
- Object
- VScripts::Config
- Defined in:
- lib/vscripts/config.rb
Overview
VScripts Configuration
Constant Summary collapse
- DOT_FILE =
User’s configuration file
"#{File.('~')}/.vscripts.yml"
- SYSTEM_CONFIG_FILE =
Global configuration file
'/etc/vscripts/config.yml'
- GLOBAL_DEFAULTS =
Global defaults
{}
Instance Attribute Summary collapse
-
#get ⇒ Hash
readonly
All configuration options.
Instance Method Summary collapse
-
#check_config(file) ⇒ Boolean
True if the file exists.
-
#initialize(config_file = nil) ⇒ Hash
constructor
Loads class.
-
#options ⇒ Hash
Parses the configuration files in order.
-
#parse(file) ⇒ Hash
Parses the configuration.
-
#read(file) ⇒ String
The contents of the file.
Constructor Details
#initialize(config_file = nil) ⇒ Hash
Loads class
19 20 21 22 |
# File 'lib/vscripts/config.rb', line 19 def initialize(config_file = nil) @file = config_file @get = GLOBAL_DEFAULTS.merge() end |
Instance Attribute Details
#get ⇒ Hash (readonly)
Returns all configuration options.
14 15 16 |
# File 'lib/vscripts/config.rb', line 14 def get @get end |
Instance Method Details
#check_config(file) ⇒ Boolean
Returns true if the file exists.
48 49 50 |
# File 'lib/vscripts/config.rb', line 48 def check_config(file) file && File.exist?(file) end |
#options ⇒ Hash
Parses the configuration files in order
26 27 28 29 30 31 |
# File 'lib/vscripts/config.rb', line 26 def parse(@file) || parse(DOT_FILE) || parse(SYSTEM_CONFIG_FILE) || {} end |
#parse(file) ⇒ Hash
Parses the configuration
36 37 38 |
# File 'lib/vscripts/config.rb', line 36 def parse(file) YAML.load(read(file)) if check_config(file) end |
#read(file) ⇒ String
Returns the contents of the file.
42 43 44 |
# File 'lib/vscripts/config.rb', line 42 def read(file) File.read(file) end |