Class: Vines::Config::Host
- Inherits:
-
Object
- Object
- Vines::Config::Host
- Defined in:
- lib/vines/config/host.rb
Overview
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.
Instance Attribute Summary collapse
-
#pubsubs ⇒ Object
readonly
Returns the value of attribute pubsubs.
Instance Method Summary collapse
- #component?(domain) ⇒ Boolean
- #components(options = nil) ⇒ Object
- #cross_domain_messages(enabled) ⇒ Object
- #cross_domain_messages? ⇒ Boolean
- #disco_items ⇒ Object
-
#initialize(config, name, &block) ⇒ Host
constructor
A new instance of Host.
- #password(domain) ⇒ Object
- #private_storage(enabled) ⇒ Object
- #private_storage? ⇒ Boolean
- #pubsub(*domains) ⇒ Object
- #pubsub?(domain) ⇒ Boolean
- #storage(name = nil, &block) ⇒ Object
-
#unsubscribe_pubsub(jid) ⇒ Object
Unsubscribe this JID from all pubsub topics hosted at this virtual host.
Constructor Details
#initialize(config, name, &block) ⇒ Host
Returns a new instance of Host.
12 13 14 15 16 17 18 19 20 21 |
# 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 @components, @pubsubs = {}, {} validate_domain(@name) instance_eval(&block) raise "storage required for #{@name}" unless @storage end |
Instance Attribute Details
#pubsubs ⇒ Object (readonly)
Returns the value of attribute pubsubs.
10 11 12 |
# File 'lib/vines/config/host.rb', line 10 def pubsubs @pubsubs end |
Instance Method Details
#component?(domain) ⇒ Boolean
57 58 59 |
# File 'lib/vines/config/host.rb', line 57 def component?(domain) !!@components[domain.to_s] end |
#components(options = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vines/config/host.rb', line 40 def components(=nil) return @components unless names = .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) .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) ⇒ Object
32 33 34 |
# File 'lib/vines/config/host.rb', line 32 def (enabled) @cross_domain_messages = !!enabled end |
#cross_domain_messages? ⇒ Boolean
36 37 38 |
# File 'lib/vines/config/host.rb', line 36 def @cross_domain_messages end |
#disco_items ⇒ Object
93 94 95 |
# File 'lib/vines/config/host.rb', line 93 def disco_items [@components.keys, @pubsubs.keys].flatten.sort end |
#password(domain) ⇒ Object
61 62 63 |
# File 'lib/vines/config/host.rb', line 61 def password(domain) @components[domain.to_s] end |
#private_storage(enabled) ⇒ Object
97 98 99 |
# File 'lib/vines/config/host.rb', line 97 def private_storage(enabled) @private_storage = !!enabled end |
#private_storage? ⇒ Boolean
101 102 103 |
# File 'lib/vines/config/host.rb', line 101 def private_storage? @private_storage end |
#pubsub(*domains) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vines/config/host.rb', line 65 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) ⇒ Boolean
80 81 82 |
# File 'lib/vines/config/host.rb', line 80 def pubsub?(domain) @pubsubs.key?(domain.to_s) end |
#storage(name = nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/vines/config/host.rb', line 23 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) ⇒ Object
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.
87 88 89 90 91 |
# File 'lib/vines/config/host.rb', line 87 def unsubscribe_pubsub(jid) @pubsubs.values.each do |pubsub| pubsub.unsubscribe_all(jid) end end |