Class: Live::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/live/resolver.rb

Overview

Resolves a client-side tag into a server-side instance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResolver

Returns a new instance of Resolver.



33
34
35
# File 'lib/live/resolver.rb', line 33

def initialize
  @allowed = {}
end

Instance Attribute Details

#allowedObject (readonly)

Returns the value of attribute allowed.



37
38
39
# File 'lib/live/resolver.rb', line 37

def allowed
  @allowed
end

Class Method Details

.allow(*arguments) ⇒ Object

Creates an instance of the resolver, allowing the specified classes to be resolved.



29
30
31
# File 'lib/live/resolver.rb', line 29

def self.allow(*arguments)
  self.new.allow(*arguments).freeze
end

Instance Method Details

#allow(*arguments) ⇒ Object

Allow the specified classes to be resolved.



48
49
50
51
52
53
54
# File 'lib/live/resolver.rb', line 48

def allow(*arguments)
  arguments.each do |klass|
    @allowed[klass.name] = klass
  end
  
  return self
end

#call(id, data) ⇒ Object

Resolve a tag.



60
61
62
63
64
# File 'lib/live/resolver.rb', line 60

def call(id, data)
  if klass = @allowed[data[:class]]
    return klass.new(id, **data)
  end
end

#freezeObject



39
40
41
42
43
44
45
# File 'lib/live/resolver.rb', line 39

def freeze
  return self unless frozen?
  
  @allowed.freeze
  
  super
end