Class: Qusion::AmqpConfig
- Inherits:
-
Object
- Object
- Qusion::AmqpConfig
- Defined in:
- lib/qusion/amqp_config.rb
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#framework_env ⇒ Object
readonly
Returns the value of attribute framework_env.
Instance Method Summary collapse
- #amqp_opts(config_hash) ⇒ Object
- #config_opts ⇒ Object
- #framework_amqp_opts(config_hash) ⇒ Object
-
#initialize(opts = nil) ⇒ AmqpConfig
constructor
A new instance of AmqpConfig.
- #load_amqp_config_file ⇒ Object
- #load_config_opts ⇒ Object
- #load_framework_config ⇒ Object
- #symbolize_keys(config_hash) ⇒ Object
Constructor Details
#initialize(opts = nil) ⇒ AmqpConfig
Returns a new instance of AmqpConfig.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/qusion/amqp_config.rb', line 9 def initialize(opts=nil) if opts && opts.respond_to?(:keys) @config_path = nil @config_opts = opts elsif opts @config_path = opts else load_framework_config end end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
7 8 9 |
# File 'lib/qusion/amqp_config.rb', line 7 def config_path @config_path end |
#framework_env ⇒ Object (readonly)
Returns the value of attribute framework_env.
7 8 9 |
# File 'lib/qusion/amqp_config.rb', line 7 def framework_env @framework_env end |
Instance Method Details
#amqp_opts(config_hash) ⇒ Object
45 46 47 |
# File 'lib/qusion/amqp_config.rb', line 45 def amqp_opts(config_hash) symbolize_keys(config_hash.first.last) end |
#config_opts ⇒ Object
25 26 27 |
# File 'lib/qusion/amqp_config.rb', line 25 def config_opts @config_opts ||= load_config_opts end |
#framework_amqp_opts(config_hash) ⇒ Object
41 42 43 |
# File 'lib/qusion/amqp_config.rb', line 41 def framework_amqp_opts(config_hash) symbolize_keys(config_hash[framework_env.to_s]) end |
#load_amqp_config_file ⇒ Object
55 56 57 58 59 60 |
# File 'lib/qusion/amqp_config.rb', line 55 def load_amqp_config_file begin YAML.load_file(config_path) rescue Errno::ENOENT end end |
#load_config_opts ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/qusion/amqp_config.rb', line 29 def load_config_opts if config_path && config_from_yaml = load_amqp_config_file if framework_env framework_amqp_opts(config_from_yaml) else amqp_opts(config_from_yaml) end else {} end end |
#load_framework_config ⇒ Object
20 21 22 23 |
# File 'lib/qusion/amqp_config.rb', line 20 def load_framework_config @config_path = "#{Rails.root}/config/amqp.yml" @framework_env = Rails.env end |
#symbolize_keys(config_hash) ⇒ Object
49 50 51 52 53 |
# File 'lib/qusion/amqp_config.rb', line 49 def symbolize_keys(config_hash) symbolized_hsh = {} config_hash.each {|option, value| symbolized_hsh[option.to_sym] = value } symbolized_hsh end |