Class: ActionSubscriber::Configuration
- Inherits:
-
Object
- Object
- ActionSubscriber::Configuration
- Defined in:
- lib/action_subscriber/configuration.rb
Constant Summary collapse
- CONFIGURATION_MUTEX =
::Mutex.new
- DEFAULTS =
{ :allow_low_priority_methods => false, :default_exchange => 'events', :heartbeat => 5, :host => 'localhost', :hosts => [], :port => 5672, :prefetch => 2, :seconds_to_wait_for_graceful_shutdown => 30, :threadpool_size => 8, :timeout => 1, :username => "guest", :password => "guest", :virtual_host => "/" }
Instance Attribute Summary collapse
-
#allow_low_priority_methods ⇒ Object
Returns the value of attribute allow_low_priority_methods.
-
#decoder ⇒ Object
Returns the value of attribute decoder.
-
#default_exchange ⇒ Object
Returns the value of attribute default_exchange.
-
#error_handler ⇒ Object
Returns the value of attribute error_handler.
-
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
-
#host ⇒ Object
Returns the value of attribute host.
-
#hosts ⇒ Object
Returns the value of attribute hosts.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#prefetch ⇒ Object
Returns the value of attribute prefetch.
-
#seconds_to_wait_for_graceful_shutdown ⇒ Object
Returns the value of attribute seconds_to_wait_for_graceful_shutdown.
-
#threadpool_size ⇒ Object
Returns the value of attribute threadpool_size.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#username ⇒ Object
Returns the value of attribute username.
-
#virtual_host ⇒ Object
Returns the value of attribute virtual_host.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_decoder(decoders) ⇒ Object
Instance Methods.
- #connection_string=(url) ⇒ Object
-
#initialize ⇒ Configuration
constructor
Instance Methods.
- #inspect ⇒ Object
- #middleware ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Instance Methods
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/action_subscriber/configuration.rb', line 68 def initialize self.decoder = { 'application/json' => lambda { |payload| JSON.parse(payload) }, 'text/plain' => lambda { |payload| payload.dup } } self.error_handler = lambda { |error, env_hash| raise } DEFAULTS.each_pair do |key, value| self.__send__("#{key}=", value) end end |
Instance Attribute Details
#allow_low_priority_methods ⇒ Object
Returns the value of attribute allow_low_priority_methods.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def allow_low_priority_methods @allow_low_priority_methods end |
#decoder ⇒ Object
Returns the value of attribute decoder.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def decoder @decoder end |
#default_exchange ⇒ Object
Returns the value of attribute default_exchange.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def default_exchange @default_exchange end |
#error_handler ⇒ Object
Returns the value of attribute error_handler.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def error_handler @error_handler end |
#heartbeat ⇒ Object
Returns the value of attribute heartbeat.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def heartbeat @heartbeat end |
#host ⇒ Object
Returns the value of attribute host.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def host @host end |
#hosts ⇒ Object
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def hosts @hosts end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def port @port end |
#prefetch ⇒ Object
Returns the value of attribute prefetch.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def prefetch @prefetch end |
#seconds_to_wait_for_graceful_shutdown ⇒ Object
Returns the value of attribute seconds_to_wait_for_graceful_shutdown.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def seconds_to_wait_for_graceful_shutdown @seconds_to_wait_for_graceful_shutdown end |
#threadpool_size ⇒ Object
Returns the value of attribute threadpool_size.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def threadpool_size @threadpool_size end |
#timeout ⇒ Object
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def timeout @timeout end |
#username ⇒ Object
Returns the value of attribute username.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def username @username end |
#virtual_host ⇒ Object
Returns the value of attribute virtual_host.
6 7 8 |
# File 'lib/action_subscriber/configuration.rb', line 6 def virtual_host @virtual_host end |
Class Method Details
.configure_from_yaml_and_cli(cli_options = {}, reload = false) ⇒ Object
Class Methods
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/action_subscriber/configuration.rb', line 43 def self.configure_from_yaml_and_cli( = {}, reload = false) CONFIGURATION_MUTEX.synchronize do @configure_from_yaml_and_cli = nil if reload @configure_from_yaml_and_cli ||= begin env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["APP_ENV"] || "development" yaml_config = {} absolute_config_path = ::File.(::File.join("config", "action_subscriber.yml")) if ::File.exists?(absolute_config_path) yaml_config = ::YAML.load_file(absolute_config_path)[env] end ::ActionSubscriber::Configuration::DEFAULTS.each_pair do |key, value| setting = [key] || yaml_config[key.to_s] ::ActionSubscriber.config.__send__("#{key}=", setting) if setting end true end end end |
Instance Method Details
#add_decoder(decoders) ⇒ Object
Instance Methods
84 85 86 87 88 89 90 91 92 |
# File 'lib/action_subscriber/configuration.rb', line 84 def add_decoder(decoders) decoders.each_pair do |content_type, decoder| unless decoder.arity == 1 raise "ActionSubscriber decoders must have an arity of 1. The #{content_type} decoder was given with arity of #{decoder.arity}." end end self.decoder.merge!(decoders) end |
#connection_string=(url) ⇒ Object
94 95 96 97 98 99 |
# File 'lib/action_subscriber/configuration.rb', line 94 def connection_string=(url) settings = ::ActionSubscriber::URI.parse_amqp_url(url) settings.each do |key, value| send("#{key}=", value) end end |
#inspect ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/action_subscriber/configuration.rb', line 110 def inspect inspection_string = " Rabbit Hosts: \#{hosts}\n Rabbit Port: \#{port}\n Threadpool Size: \#{threadpool_size}\n Low Priority Subscriber: \#{allow_low_priority_methods}\n Decoders:\n INSPECT\n decoder.each_key { |key| inspection_string << \" --\#{key}\\n\" }\n return inspection_string\nend\n".strip_heredoc |
#middleware ⇒ Object
106 107 108 |
# File 'lib/action_subscriber/configuration.rb', line 106 def middleware @middleware ||= Middleware.initialize_stack end |