lib/aladdin/config.rb in aladdin-0.0.6 vs lib/aladdin/config.rb in aladdin-0.0.7
- old
+ new
@@ -1,6 +1,10 @@
# ~*~ encoding: utf-8 ~*~
+require 'active_support/core_ext/hash'
+require 'json'
+require 'aladdin/constants'
+
module Aladdin
# Raised when there is a configuration error.
class ConfigError < StandardError; end
@@ -12,28 +16,29 @@
# Name of configuration file.
FILE = 'manifest.json'
# Default configuration options.
DEFAULTS = {
- 'verify' => {
+ verify: {
'bin' => 'make',
'arg_prefix' => ''
},
- 'title' => 'Lesson X',
- 'description' => 'This is a placeholder description. You should provide your own',
- 'categories' => [],
- 'static_paths' => %w(images)
+ title: 'Lesson X',
+ description: 'This is a placeholder description. You should provide your own',
+ categories: [],
+ static_paths: %w(images)
}
# 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
def initialize(root)
@path = File.expand_path FILE, root
ensure_readable
super nil
- merge! DEFAULTS.deep_merge ::JSON.parse File.read @path
+ newsets = ::JSON.parse File.read @path
+ merge! DEFAULTS.deep_merge newsets.symbolize_keys
ensure_valid
rescue ::JSON::JSONError => e
raise ConfigError.new e.message
end