Module: Hutch::Config

Defined in:
lib/hutch/config.rb

Class Method Summary collapse

Class Method Details

.check_attr(attr) ⇒ Object



38
39
40
41
42
# File 'lib/hutch/config.rb', line 38

def self.check_attr(attr)
  unless user_config.key?(attr)
    raise UnknownAttributeError, "#{attr} is not a valid config attribute"
  end
end

.get(attr) ⇒ Object Also known as: []



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

def self.get(attr)
  check_attr(attr)
  user_config[attr]
end

.initializeObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/hutch/config.rb', line 7

def self.initialize
  @config = {
    mq_host: 'localhost',
    mq_port: 5672,
    mq_exchange: 'hutch',  # TODO: should this be required?
    mq_vhost: '/',
    mq_username: 'guest',
    mq_password: 'guest',
    mq_api_host: 'localhost',
    mq_api_port: 15672,
    log_level: Logger::INFO,
    require_paths: [],
    error_handlers: [Hutch::ErrorHandlers::Logger.new]
  }
end

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



49
50
51
52
53
54
55
56
57
58
# File 'lib/hutch/config.rb', line 49

def self.method_missing(method, *args, &block)
  attr = method.to_s.sub(/=$/, '').to_sym
  return super unless user_config.key?(attr)

  if method =~ /=$/
    set(attr, args.first)
  else
    get(attr)
  end
end

.set(attr, value) ⇒ Object Also known as: []=



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

def self.set(attr, value)
  check_attr(attr)
  user_config[attr] = value
end

.user_configObject



44
45
46
47
# File 'lib/hutch/config.rb', line 44

def self.user_config
  initialize unless @config
  @config
end