Module: Ore::Config

Defined in:
lib/ore/config.rb

Constant Summary collapse

HOME =

The users home directory

Gem.user_home
PATH =

Ore config directory

File.join(HOME,'.ore')
OPTIONS_FILE =

Default options file.

File.join(PATH,'options.yml')
TEMPLATES_DIR =

Custom Ore Templates directory

File.join(PATH,'templates')
DATA_DIR =

The data/ directory for Ore

File.expand_path(File.join('..','..','data'),File.dirname(__FILE__))
@@enabled =

Specifies whether user settings will be loaded

true

Class Method Summary collapse

Class Method Details

.builtin_templates {|path| ... } ⇒ Object

The builtin templates.

Yields:

  • (path)

    The given block will be passed every builtin template.

Yield Parameters:

  • path (String)

    The path of a Ore template directory.



81
82
83
84
85
86
87
88
89
# File 'lib/ore/config.rb', line 81

def Config.builtin_templates
  path = File.join(DATA_DIR,'ore','templates')

  if File.directory?(path)
    Dir.glob("#{path}/*") do |template|
      yield template if File.directory?(template)
    end
  end
end

.disable!Object

Disables access to user settings.

Since:

  • 0.5.0



38
39
40
# File 'lib/ore/config.rb', line 38

def Config.disable!
  @@enabled = false
end

.enable!Object

Enables access to user settings.

Since:

  • 0.5.0



29
30
31
# File 'lib/ore/config.rb', line 29

def Config.enable!
  @@enabled = true
end

.installed_templates {|path| ... } ⇒ Object

The installed templates.

Yields:

  • (path)

    The given block will be passed every installed template.

Yield Parameters:

  • path (String)

    The path of a Ore template directory.



100
101
102
103
104
105
106
107
108
# File 'lib/ore/config.rb', line 100

def Config.installed_templates
  if @@enabled
    if File.directory?(TEMPLATES_DIR)
      Dir.glob("#{TEMPLATES_DIR}/*") do |template|
        yield template if File.directory?(template)
      end
    end
  end
end

.optionsHash

Loads the default options from ~/.ore/options.yml.

Returns:

  • (Hash)

    The loaded default options.

Raises:

  • (RuntimeError)

    The ~/.ore/options.yml did not contain a YAML encoded Hash.

Since:

  • 0.9.0



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ore/config.rb', line 53

def Config.options
  options = {}

  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")
    end

    new_options.each do |name,value|
      options[name.to_sym] = value
    end
  end

  return options
end