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



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

def initialize
  @allowed = {}
end

Instance Attribute Details

#A map of allowed class names.(mapofallowed) ⇒ Object (readonly)



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

attr :allowed

#allowedObject (readonly)

Returns the value of attribute allowed.



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

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.



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

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

#call(id, data) ⇒ Object

Resolve a tag.



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

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

#freezeObject



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

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