module Diversion::Configurable
Attributes
encode_uris[RW]
host[RW]
path[RW]
port[RW]
sign_key[RW]
sign_length[RW]
url_decoding[RW]
url_encoding[RW]
Public Class Methods
keys()
click to toggle source
# File lib/diversion/configurable.rb, line 13 def keys @keys ||= [ :host, :port, :path, :sign_key, :sign_length, :encode_uris, :url_encoding, :url_decoding ] end
Public Instance Methods
configure() { |self| ... }
click to toggle source
# File lib/diversion/configurable.rb, line 28 def configure yield self validate_configuration! self end
reset!()
click to toggle source
# File lib/diversion/configurable.rb, line 34 def reset! @host = 'http://localhost.domain' @port = 80 @path = '/redirect/1/' @sign_length = 0 @sign_key = nil @encode_uris = ['http','https'] @url_encoding = Encode::Params @url_decoding = Decode::Params validate_configuration! self end
Also aliased as: setup
Private Instance Methods
options()
click to toggle source
@return [Hash]
# File lib/diversion/configurable.rb, line 51 def options Hash[Diversion::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}] end
validate_configuration!()
click to toggle source
Ensures that all configuration parameters are of an expected type.
@raise [Diversion::Error::ConfigurationError] Error
is raised when
supplied configuration is not of expected type
# File lib/diversion/configurable.rb, line 59 def validate_configuration! unless @host.is_a?(String) && @host.length > 0 raise(Error::ConfigurationError, "Invalid host specified: Host must contain the host to redirect to.") end if @host.end_with?('/') raise(Error::ConfigurationError, "Invalid host specified: #{@host} should not end with a trailing slash.") end unless @path.is_a?(String) && @path.length > 0 raise(Error::ConfigurationError, "Invalid path specified: Path must contain a path to redirect to.") end unless @path.end_with?('/') raise(Error::ConfigurationError, "Invalid path specified: #{@path} should end with a trailing slash.") end unless @port.is_a?(Integer) && @port > 0 raise(Error::ConfigurationError, "Invalid port specified: #{@port} must be an integer and non-zero.") end if !@sign_key.nil? && !@sign_key.is_a?(String) raise(Error::ConfigurationError, "Invalid sign_key specified: #{@sign_key} must be a String.") end unless @sign_length.is_a?(Integer) && @sign_length.between?(0, Signing::MAX_SIGN_LENGTH) raise(Error::ConfigurationError, "Invalid sign_length specified: #{@sign_length} must be an integer between 0-#{Signing::MAX_SIGN_LENGTH}.") end unless @encode_uris.is_a?(Array) && @encode_uris.count > 0 raise(Error::ConfigurationError, "Invalid encode_uris specified: #{@encode_uris} must be an array with at least one URI scheme.") end unless @url_encoding.is_a?(Module) && Encode::ENCODERS.include?(@url_encoding) raise(Error::ConfigurationError, "Invalid url_encoding specified: #{@url_encoding} must be a valid encoder module.") end unless @url_decoding.is_a?(Module) && Decode::DECODERS.include?(@url_decoding) raise(Error::ConfigurationError, "Invalid url_decoding specified: #{@url_decoding} must be a valid decoder module.") end end