Class: Vines::Config
- Inherits:
-
Object
- Object
- Vines::Config
- Defined in:
- lib/vines/config.rb
Overview
A Config object is passed to the stream handlers to give them access to server configuration information like virtual host names, storage systems, etc. This class provides the DSL methods used in the config/vines.rb file.
Defined Under Namespace
Classes: ClientPort, ComponentPort, Host, HttpPort, Port, ServerPort
Constant Summary collapse
- LOG_LEVELS =
%w[debug info warn error fatal].freeze
- @@instance =
nil
Instance Attribute Summary collapse
-
#vhosts ⇒ Object
readonly
Returns the value of attribute vhosts.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](name) ⇒ Object
Retrieve the Port subclass with this name: [:client, :server, :http, :component].
- #host(*names, &block) ⇒ Object
-
#initialize(&block) ⇒ Config
constructor
A new instance of Config.
- #log(level) ⇒ Object
- #ports ⇒ Object
-
#s2s?(domain) ⇒ Boolean
Returns true if server-to-server connections are allowed with the given domain.
- #vhost?(domain) ⇒ Boolean
Constructor Details
#initialize(&block) ⇒ Config
Returns a new instance of Config.
23 24 25 26 27 |
# File 'lib/vines/config.rb', line 23 def initialize(&block) @vhosts, @ports = {}, {} instance_eval(&block) raise "must define at least one virtual host" if @vhosts.empty? end |
Instance Attribute Details
#vhosts ⇒ Object (readonly)
Returns the value of attribute vhosts.
12 13 14 |
# File 'lib/vines/config.rb', line 12 def vhosts @vhosts end |
Class Method Details
.configure(&block) ⇒ Object
15 16 17 |
# File 'lib/vines/config.rb', line 15 def self.configure(&block) @@instance = self.new(&block) end |
.instance ⇒ Object
19 20 21 |
# File 'lib/vines/config.rb', line 19 def self.instance @@instance end |
Instance Method Details
#[](name) ⇒ Object
Retrieve the Port subclass with this name:
- :client, :server, :http, :component
72 73 74 |
# File 'lib/vines/config.rb', line 72 def [](name) @ports[name] or raise ArgumentError.new("no port named #{name}") end |
#host(*names, &block) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/vines/config.rb', line 29 def host(*names, &block) names = names.flatten.map {|name| name.downcase } dupes = names.uniq.size != names.size || (@vhosts.keys & names).any? raise "one host definition per domain allowed" if dupes names.each do |name| @vhosts.merge! Host.new(name, &block).to_hash end end |
#log(level) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/vines/config.rb', line 48 def log(level) const = Logger.const_get(level.to_s.upcase) rescue nil unless LOG_LEVELS.include?(level.to_s) && const raise "log level must be one of: #{LOG_LEVELS.join(', ')}" end Class.new.extend(Vines::Log).log.level = const end |
#ports ⇒ Object
56 57 58 |
# File 'lib/vines/config.rb', line 56 def ports @ports.values end |
#s2s?(domain) ⇒ Boolean
Returns true if server-to-server connections are allowed with the given domain.
66 67 68 |
# File 'lib/vines/config.rb', line 66 def s2s?(domain) @ports[:server] && @ports[:server].hosts.include?(domain) end |
#vhost?(domain) ⇒ Boolean
60 61 62 |
# File 'lib/vines/config.rb', line 60 def vhost?(domain) @vhosts.key?(domain) end |