lib/ore/config.rb in ore-0.8.1 vs lib/ore/config.rb in ore-0.9.0

- old
+ new

@@ -1,28 +1,28 @@ +require 'rubygems' require 'pathname' -require 'env' module Ore module Config - # Specifies whether user settings will be loaded - @@enabled = true - # The users home directory - @@home = Env.home + HOME = Gem.user_home # Ore config directory - @@path = File.join(@@home,'.ore') + PATH = File.join(HOME,'.ore') # Default options file. - @@options_file = File.join(@@path,'options.yml') + OPTIONS_FILE = File.join(PATH,'options.yml') # Custom Ore Templates directory - @@templates_dir = File.join(@@path,'templates') + TEMPLATES_DIR = File.join(PATH,'templates') # The `data/` directory for Ore - @@data_dir = File.expand_path(File.join('..','..','data'),File.dirname(__FILE__)) + DATA_DIR = File.expand_path(File.join('..','..','data'),File.dirname(__FILE__)) + # Specifies whether user settings will be loaded + @@enabled = true + # # Enables access to user settings. # # @since 0.5.0 # @@ -46,21 +46,21 @@ # The loaded default options. # # @raise [RuntimeError] # The `~/.ore/options.yml` did not contain a YAML encoded Hash. # - # @since 0.5.0 + # @since 0.9.0 # - def Config.default_options + def Config.options options = {} - if (@@enabled && File.file?(@@options_file)) - new_options = YAML.load_file(@@options_file) + if (@@enabled && File.file?(OPTIONS_FILE)) + new_options = YAML.load_file(OPTIONS_FILE) # default options must be a Hash unless new_options.kind_of?(Hash) - raise("#{@@options_file} must contain a YAML encoded Hash") + raise("#{OPTIONS_FILE} must contain a YAML encoded Hash") end new_options.each do |name,value| options[name.to_sym] = value end @@ -77,11 +77,11 @@ # # @yieldparam [String] path # The path of a Ore template directory. # def Config.builtin_templates - path = File.join(@@data_dir,'ore','templates') + path = File.join(DATA_DIR,'ore','templates') if File.directory?(path) Dir.glob("#{path}/*") do |template| yield template if File.directory?(template) end @@ -96,14 +96,14 @@ # # @yieldparam [String] path # The path of a Ore template directory. # def Config.installed_templates - return unless @@enabled - - if File.directory?(@@templates_dir) - Dir.glob("#{@@templates_dir}/*") do |template| - yield template if File.directory?(template) + if @@enabled + if File.directory?(TEMPLATES_DIR) + Dir.glob("#{TEMPLATES_DIR}/*") do |template| + yield template if File.directory?(template) + end end end end end end