Class: Rbrc::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rbrc/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/rbrc/config.rb', line 6

def initialize(name, options={})
  @name = name
  ensure_file_exists
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



27
28
29
# File 'lib/rbrc/config.rb', line 27

def method_missing(sym, *args, &block)
  return self[sym]
end

Class Method Details

.method_missing(sym, *args, &block) ⇒ Object



37
38
39
40
41
# File 'lib/rbrc/config.rb', line 37

def method_missing(sym, *args, &block)
  return Registry[sym] if Registry[sym]

  super(sym, *args, &block)
end

.register(config, options = {}) ⇒ Object



33
34
35
# File 'lib/rbrc/config.rb', line 33

def register(config, options={})
  Rbrc::Registry.register_config(config, options)
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
# File 'lib/rbrc/config.rb', line 19

def [](key)
  values[key.to_s]
end

#ensure_file_existsObject



23
24
25
# File 'lib/rbrc/config.rb', line 23

def ensure_file_exists
  raise ConfigFileDoesNotExistError unless File.exist?(file_path)
end

#file_pathObject



11
12
13
# File 'lib/rbrc/config.rb', line 11

def file_path
  @file_path ||= File.expand_path("~/.#{@name}rc")
end

#valuesObject



15
16
17
# File 'lib/rbrc/config.rb', line 15

def values
  ParseConfig.new(file_path).params
end