class Aladdin::Config

Configuration options for Aladdin. Gets all of its values from {::Spirit::MANIFEST}. Values in this file should not be trusted because they are given by the user.

Constants

DEFAULTS

Default configuration options.

Public Class Methods

new(root) click to toggle source

Creates a new configuration from the file at the given path. Merges the configuration hash parsed from the file with {DEFAULTS}. Raises {ConfigError} if the file could not be read or parsed. @param [String] root path to lesson root

Calls superclass method
# File lib/aladdin/config.rb, line 32
def initialize(root)
  super nil
  @path = File.join root, Spirit::MANIFEST
  ensure_readable
  merge! DEFAULTS.deep_merge Spirit::Manifest.load_file @path
rescue Spirit::Error => e
  not_parseable e
end

Private Instance Methods

ensure_readable() click to toggle source

Raises {ConfigError} unless the configuration file exists and is readable.

# File lib/aladdin/config.rb, line 45
def ensure_readable
  missing unless File.exist? @path
  not_readable unless File.readable? @path
end
missing() click to toggle source
# File lib/aladdin/config.rb, line 50
    def missing
      raise ConfigError, <<-eos.squish
        We expected a manifest file at #{@path}, but couldn't find it. Please
        ensure that you have a file named #{Spirit::MANIFEST} at the root
        of your lesson directory.
      eos
    end
not_parseable(e) click to toggle source
# File lib/aladdin/config.rb, line 65
    def not_parseable(e)
      raise ConfigError, <<-eos.strip_heredoc
      We found a manifest file at #{@path}, but couldn't parse it. The following error message was returned from the parser:
          #{e.message}
      eos
    end
not_readable() click to toggle source
# File lib/aladdin/config.rb, line 58
    def not_readable
      raise ConfigError, <<-eos.squish
        We found a manifest file at #{@path}, but couldn't open it for reading.
        Please ensure that you have the permissions to read the file.
      eos
    end