Class: ActivePublisher::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_publisher/configuration.rb

Constant Summary collapse

CONFIGURATION_MUTEX =
::Mutex.new
DEFAULTS =
{
  :error_handler => lambda { |error, env_hash|
    ::ActivePublisher::Logging.logger.error(error.class)
    ::ActivePublisher::Logging.logger.error(error.message)
    ::ActivePublisher::Logging.logger.error(error.backtrace.join("\n")) if error.backtrace.respond_to?(:join)
  },
  :heartbeat => 5,
  :host => "localhost",
  :hosts => [],
  :password => "guest",
  :port => 5672,
  :publisher_confirms => false,
  :publisher_confirms_timeout => 5_000, #specified as a number of milliseconds
  :seconds_to_wait_for_graceful_shutdown => 30,
  :timeout => 1,
  :tls => false,
  :tls_ca_certificates => [],
  :tls_cert => nil,
  :tls_key => nil,
  :username => "guest",
  :verify_peer => true,
  :virtual_host => "/"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Instance Methods



88
89
90
91
92
# File 'lib/active_publisher/configuration.rb', line 88

def initialize
  DEFAULTS.each_pair do |key, value|
    self.__send__("#{key}=", value)
  end
end

Instance Attribute Details

#error_handlerObject

Returns the value of attribute error_handler.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def error_handler
  @error_handler
end

#heartbeatObject

Returns the value of attribute heartbeat.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def heartbeat
  @heartbeat
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def host
  @host
end

#hostsObject

Returns the value of attribute hosts.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def hosts
  @hosts
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def password
  @password
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def port
  @port
end

#publisher_confirmsObject

Returns the value of attribute publisher_confirms.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def publisher_confirms
  @publisher_confirms
end

#publisher_confirms_timeoutObject

Returns the value of attribute publisher_confirms_timeout.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def publisher_confirms_timeout
  @publisher_confirms_timeout
end

#seconds_to_wait_for_graceful_shutdownObject

Returns the value of attribute seconds_to_wait_for_graceful_shutdown.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def seconds_to_wait_for_graceful_shutdown
  @seconds_to_wait_for_graceful_shutdown
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def timeout
  @timeout
end

#tlsObject

Returns the value of attribute tls.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def tls
  @tls
end

#tls_ca_certificatesObject

Returns the value of attribute tls_ca_certificates.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def tls_ca_certificates
  @tls_ca_certificates
end

#tls_certObject

Returns the value of attribute tls_cert.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def tls_cert
  @tls_cert
end

#tls_keyObject

Returns the value of attribute tls_key.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def tls_key
  @tls_key
end

#usernameObject

Returns the value of attribute username.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def username
  @username
end

#verify_peerObject

Returns the value of attribute verify_peer.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def verify_peer
  @verify_peer
end

#virtual_hostObject

Returns the value of attribute virtual_host.



5
6
7
# File 'lib/active_publisher/configuration.rb', line 5

def virtual_host
  @virtual_host
end

Class Method Details

.configure_from_yaml_and_cli(cli_options = {}, reload = false) ⇒ Object

Class Methods



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/active_publisher/configuration.rb', line 52

def self.configure_from_yaml_and_cli(cli_options = {}, 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 = attempt_to_load_yaml_file(env)
      DEFAULTS.each_pair do |key, value|
        setting = cli_options[key] || cli_options[key.to_s] || yaml_config[key] || yaml_config[key.to_s]
        ::ActivePublisher.configuration.public_send("#{key}=", setting) if setting
      end

      true
    end
  end
end

Instance Method Details

#connection_string=(url) ⇒ Object



94
95
96
97
98
99
# File 'lib/active_publisher/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