Module: ActiveMessage::Configuration
- Defined in:
- lib/active_message/configuration.rb
Class Method Summary collapse
- .check_attr(attr) ⇒ Object
- .get(attr) ⇒ Object (also: [])
- .initialize ⇒ 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
40 41 42 43 44 |
# File 'lib/active_message/configuration.rb', line 40 def self.check_attr(attr) unless user_config.key?(attr) raise ActiveMessage::UnknownAttributeError, "#{attr} is not a valid config attribute" end end |
.get(attr) ⇒ Object Also known as: []
20 21 22 23 |
# File 'lib/active_message/configuration.rb', line 20 def self.get(attr) check_attr(attr) user_config[attr] end |
.initialize ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_message/configuration.rb', line 5 def self.initialize @config = { host: 'localhost', port: 5672, exchange: 'ActiveMessage', vhost: '/', tls: false, tls_cert: nil, tls_key: nil, tls_ca_certificates: [], username: 'dustin', password: '' } end |
.load_from_file(file) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/active_message/configuration.rb', line 46 def self.load_from_file(file) temp = YAML.load(File.read(file))[Rails.env] temp.each do |attr, value| ActiveMessage::Configuration.send("#{attr}=", value) end end |
.method_missing(method, *args, &block) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/active_message/configuration.rb', line 53 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: []=
25 26 27 28 |
# File 'lib/active_message/configuration.rb', line 25 def self.set(attr, value) check_attr(attr) user_config[attr] = value end |
.user_config ⇒ Object
35 36 37 38 |
# File 'lib/active_message/configuration.rb', line 35 def self.user_config initialize unless @config @config end |