class Vines::Config::Host
Provides the DSL methods for the virtual host definitions in the conf/config.rb file. Host
instances can be accessed at runtime through the +Config#vhosts+ method.
Attributes
pubsubs[R]
Public Class Methods
new(config, name, &block)
click to toggle source
# File lib/vines/config/host.rb, line 12 def initialize(config, name, &block) @config, @name = config, name.downcase @storage = nil @cross_domain_messages = false @private_storage = false @accept_self_signed = false @force_s2s_encryption = false @components, @pubsubs = {}, {} validate_domain(@name) instance_eval(&block) raise "storage required for #{@name}" unless @storage end
Public Instance Methods
accept_self_signed(enabled)
click to toggle source
# File lib/vines/config/host.rb, line 42 def accept_self_signed(enabled) @accept_self_signed = !!enabled end
accept_self_signed?()
click to toggle source
# File lib/vines/config/host.rb, line 46 def accept_self_signed? @accept_self_signed end
component?(domain)
click to toggle source
# File lib/vines/config/host.rb, line 75 def component?(domain) !!@components[domain.to_s] end
components(options=nil)
click to toggle source
# File lib/vines/config/host.rb, line 58 def components(options=nil) return @components unless options names = options.keys.map {|domain| "#{domain}.#{@name}".downcase } raise "duplicate component domains not allowed" if dupes?(names, @components.keys) raise "pubsub domains overlap component domains" if dupes?(names, @pubsubs.keys) options.each do |domain, password| raise 'component domain required' if (domain || '').to_s.strip.empty? raise 'component password required' if (password || '').strip.empty? name = "#{domain}.#{@name}".downcase raise "components must be one level below their host: #{name}" if domain.to_s.include?('.') validate_domain(name) @components[name] = password end end
cross_domain_messages(enabled)
click to toggle source
# File lib/vines/config/host.rb, line 50 def cross_domain_messages(enabled) @cross_domain_messages = !!enabled end
cross_domain_messages?()
click to toggle source
# File lib/vines/config/host.rb, line 54 def cross_domain_messages? @cross_domain_messages end
disco_items()
click to toggle source
# File lib/vines/config/host.rb, line 111 def disco_items [@components.keys, @pubsubs.keys].flatten.sort end
force_s2s_encryption(enabled)
click to toggle source
# File lib/vines/config/host.rb, line 34 def force_s2s_encryption(enabled) @force_s2s_encryption = !!enabled end
force_s2s_encryption?()
click to toggle source
# File lib/vines/config/host.rb, line 38 def force_s2s_encryption? @force_s2s_encryption end
password(domain)
click to toggle source
# File lib/vines/config/host.rb, line 79 def password(domain) @components[domain.to_s] end
private_storage(enabled)
click to toggle source
# File lib/vines/config/host.rb, line 115 def private_storage(enabled) @private_storage = !!enabled end
private_storage?()
click to toggle source
# File lib/vines/config/host.rb, line 119 def private_storage? @private_storage end
pubsub(*domains)
click to toggle source
# File lib/vines/config/host.rb, line 83 def pubsub(*domains) domains.flatten! raise 'define at least one pubsub domain' if domains.empty? names = domains.map {|domain| "#{domain}.#{@name}".downcase } raise "duplicate pubsub domains not allowed" if dupes?(names, @pubsubs.keys) raise "pubsub domains overlap component domains" if dupes?(names, @components.keys) domains.each do |domain| raise 'pubsub domain required' if (domain || '').to_s.strip.empty? name = "#{domain}.#{@name}".downcase raise "pubsub domains must be one level below their host: #{name}" if domain.to_s.include?('.') validate_domain(name) @pubsubs[name] = PubSub.new(@config, name) end end
pubsub?(domain)
click to toggle source
# File lib/vines/config/host.rb, line 98 def pubsub?(domain) @pubsubs.key?(domain.to_s) end
storage(name=nil, &block)
click to toggle source
# File lib/vines/config/host.rb, line 25 def storage(name=nil, &block) if name raise "one storage mechanism per host allowed" if @storage @storage = Storage.from_name(name, &block) else @storage end end
unsubscribe_pubsub(jid)
click to toggle source
Unsubscribe this JID
from all pubsub topics hosted at this virtual host. This should be called when the user's session ends via logout or disconnect.
# File lib/vines/config/host.rb, line 105 def unsubscribe_pubsub(jid) @pubsubs.values.each do |pubsub| pubsub.unsubscribe_all(jid) end end
Private Instance Methods
dupes?(a, b)
click to toggle source
Return true if the arrays contain any duplicate items.
# File lib/vines/config/host.rb, line 126 def dupes?(a, b) a.uniq.size != a.size || b.uniq.size != b.size || (a & b).any? end
validate_domain(name)
click to toggle source
Prevent domains in config files that won't form valid JIDs.
# File lib/vines/config/host.rb, line 131 def validate_domain(name) jid = JID.new(name) raise "incorrect domain: #{name}" if jid.node || jid.resource end