Class: Chaindrive::Config
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Chaindrive::Config
- Defined in:
- lib/chaindrive/config.rb
Overview
Define the basic settings for the Chaindrive runtime environment. These are directly loaded from on-disk JSON files.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Config
constructor
Construct a JSON configuration from disk.
-
#save(filename) ⇒ Object
Write the JSON configuration file to disk.
Constructor Details
#initialize(filename) ⇒ Config
Construct a JSON configuration from disk.
11 12 13 14 |
# File 'lib/chaindrive/config.rb', line 11 def initialize(filename) # Load up the disk configuration if it exists. super MultiJson.load(IO.read(filename)) if File.exists?(filename) end |
Instance Method Details
#save(filename) ⇒ Object
Write the JSON configuration file to disk.
18 19 20 21 22 23 24 25 |
# File 'lib/chaindrive/config.rb', line 18 def save(filename) # Create the configuration directory if it does not exist. dp = File.(File.dirname(filename)) FileUtils.mkdir_p(dp) unless File.directory?(dp) fail SystemCallError, "Failed saving '#{dp}'" unless File.directory?(dp) IO.write(filename, MultiJson.dump(self, pretty: true)) end |