Class: Boom::Config
- Inherits:
-
Object
- Object
- Boom::Config
- Defined in:
- lib/kaboom/config.rb
Constant Summary collapse
- FILE =
The main config file for boom
"#{ENV['HOME']}/.boom.conf"
- REMOTE_FILE =
FILE.gsub(/\.conf$/, ".remote.conf")
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Public: The attributes Hash for configuration options.
-
#remote ⇒ Object
if set to true then we will use a different config file for storage engine.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Public: an alias for accessing Boom.config.attributes like Boom.config instead.
-
#bootstrap ⇒ Object
Public: saves an empty, barebones hash to @attributes for the purpose of new user setup.
-
#file ⇒ Object
Public: accessor for the configuration file.
-
#initialize(remote = false) ⇒ Config
constructor
Public: creates a new instance of Config.
- #invalid_message ⇒ Object
-
#load_attributes ⇒ Object
Public: loads and parses the JSON tree from disk into memory and stores it in the attributes Hash.
-
#save ⇒ Object
Public: writes the in-memory JSON Hash to disk.
Constructor Details
#initialize(remote = false) ⇒ Config
Public: creates a new instance of Config.
This will load the attributes from boom’s config file, or bootstrap it if this is a new install. Bootstrapping defaults to the JSON backend.
Returns nothing.
47 48 49 50 51 |
# File 'lib/kaboom/config.rb', line 47 def initialize remote=false @remote = remote bootstrap unless File.exist?(file) load_attributes end |
Instance Attribute Details
#attributes ⇒ Object
Public: The attributes Hash for configuration options. The attributes needed are dictated by each backend, but the ‘backend` option must be present.
30 31 32 |
# File 'lib/kaboom/config.rb', line 30 def attributes @attributes end |
#remote ⇒ Object
if set to true then we will use a different config file for storage engine
25 26 27 |
# File 'lib/kaboom/config.rb', line 25 def remote @remote end |
Instance Method Details
#[](key) ⇒ Object
Public: an alias for accessing Boom.config.attributes like Boom.config instead
Returns the value in the attributes hash
37 38 39 |
# File 'lib/kaboom/config.rb', line 37 def [] key attributes[key] end |
#bootstrap ⇒ Object
Public: saves an empty, barebones hash to @attributes for the purpose of new user setup.
Returns whether the attributes were saved.
64 65 66 67 68 69 |
# File 'lib/kaboom/config.rb', line 64 def bootstrap @attributes = { :backend => 'json' } save end |
#file ⇒ Object
Public: accessor for the configuration file.
Returns the String file path.
56 57 58 |
# File 'lib/kaboom/config.rb', line 56 def file remote ? REMOTE_FILE : FILE end |
#invalid_message ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kaboom/config.rb', line 103 def %(#{red "Is your config correct? You said:"} #{File.read Boom.config.file} #{cyan "Our survey says:"} #{self.class.sample_config} #{yellow "Go edit "} #{Boom.config.file + yellow(" and make it all better") } ).gsub(/^ {8}/, '') # strip the first eight spaces of every line end |
#load_attributes ⇒ Object
Public: loads and parses the JSON tree from disk into memory and stores it in the attributes Hash.
Returns nothing.
91 92 93 |
# File 'lib/kaboom/config.rb', line 91 def load_attributes @attributes = MultiJson.decode(File.new(file, 'r').read) end |
#save ⇒ Object
Public: writes the in-memory JSON Hash to disk.
Returns nothing.
98 99 100 101 |
# File 'lib/kaboom/config.rb', line 98 def save json = MultiJson.encode(attributes) File.open(file, 'w') {|f| f.write(json) } end |