Module: Hutch::Config
- Defined in:
- lib/hutch/config.rb
Class Method Summary collapse
- .check_attr(attr) ⇒ Object
- .get(attr) ⇒ Object (also: [])
- .initialize(params = {}) ⇒ Object
- .load_from_file(file) ⇒ Object
- .method_missing(method, *args, &block) ⇒ Object
- .set(attr, value) ⇒ Object (also: []=)
- .user_config ⇒ Object
Class Method Details
.check_attr(attr) ⇒ Object
53 54 55 56 57 |
# File 'lib/hutch/config.rb', line 53 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: []
38 39 40 41 |
# File 'lib/hutch/config.rb', line 38 def self.get(attr) check_attr(attr) user_config[attr] end |
.initialize(params = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hutch/config.rb', line 10 def self.initialize(params={}) @config = { mq_host: 'localhost', mq_port: 5672, mq_exchange: 'hutch', # TODO: should this be required? mq_vhost: '/', mq_tls: false, mq_tls_cert: nil, mq_tls_key: nil, mq_username: 'guest', mq_password: 'guest', mq_api_host: 'localhost', mq_api_port: 15672, mq_api_ssl: false, # placeholder, allows specifying connection parameters # as a URI. uri: nil, log_level: Logger::INFO, require_paths: [], autoload_rails: true, error_handlers: [Hutch::ErrorHandlers::Logger.new], namespace: nil, daemonise: false, pidfile: nil, channel_prefetch: 0 }.merge(params) end |
.load_from_file(file) ⇒ Object
64 65 66 67 68 |
# File 'lib/hutch/config.rb', line 64 def self.load_from_file(file) YAML.load(file).each do |attr, value| Hutch::Config.send("#{attr}=", value) end end |
.method_missing(method, *args, &block) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/hutch/config.rb', line 70 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: []=
43 44 45 46 |
# File 'lib/hutch/config.rb', line 43 def self.set(attr, value) check_attr(attr) user_config[attr] = value end |
.user_config ⇒ Object
59 60 61 62 |
# File 'lib/hutch/config.rb', line 59 def self.user_config initialize unless @config @config end |