Class: Vines::Config::Host

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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, @ldap = nil, 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

#pubsubsObject (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

Returns:

  • (Boolean)


63
64
65
# File 'lib/vines/config/host.rb', line 63

def component?(domain)
  !!@components[domain.to_s]
end

#components(options = nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/vines/config/host.rb', line 46

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) ⇒ Object



38
39
40
# File 'lib/vines/config/host.rb', line 38

def cross_domain_messages(enabled)
  @cross_domain_messages = !!enabled
end

#cross_domain_messages?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/vines/config/host.rb', line 42

def cross_domain_messages?
  @cross_domain_messages
end

#disco_itemsObject



99
100
101
# File 'lib/vines/config/host.rb', line 99

def disco_items
  [@components.keys, @pubsubs.keys].flatten.sort
end

#ldap(host = 'localhost', port = 636, &block) ⇒ Object



33
34
35
36
# File 'lib/vines/config/host.rb', line 33

def ldap(host='localhost', port=636, &block)
  @ldap = Storage::Ldap.new(host, port, &block)
  @storage.ldap = @ldap if @storage
end

#password(domain) ⇒ Object



67
68
69
# File 'lib/vines/config/host.rb', line 67

def password(domain)
  @components[domain.to_s]
end

#private_storage(enabled) ⇒ Object



103
104
105
# File 'lib/vines/config/host.rb', line 103

def private_storage(enabled)
  @private_storage = !!enabled
end

#private_storage?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/vines/config/host.rb', line 107

def private_storage?
  @private_storage
end

#pubsub(*domains) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/vines/config/host.rb', line 71

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

Returns:

  • (Boolean)


86
87
88
# File 'lib/vines/config/host.rb', line 86

def pubsub?(domain)
  @pubsubs.key?(domain.to_s)
end

#storage(name = nil, &block) ⇒ Object



23
24
25
26
27
28
29
30
31
# 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)
    @storage.ldap = @ldap
  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.



93
94
95
96
97
# File 'lib/vines/config/host.rb', line 93

def unsubscribe_pubsub(jid)
  @pubsubs.values.each do |pubsub|
    pubsub.unsubscribe_all(jid)
  end
end