Class: Live::Resolver
- Inherits:
-
Object
- Object
- Live::Resolver
- Defined in:
- lib/live/resolver.rb
Overview
Resolves a client-side tag into a server-side instance.
Instance Attribute Summary collapse
- #A map of allowed class names.(mapofallowed) ⇒ Object readonly
-
#allowed ⇒ Object
readonly
Returns the value of attribute allowed.
Class Method Summary collapse
-
.allow(*arguments) ⇒ Object
Creates an instance of the resolver, allowing the specified classes to be resolved.
Instance Method Summary collapse
-
#allow(*arguments) ⇒ Object
Allow the specified classes to be resolved.
-
#call(id, data) ⇒ Object
Resolve a tag.
- #freeze ⇒ Object
-
#initialize ⇒ Resolver
constructor
A new instance of Resolver.
Constructor Details
#initialize ⇒ Resolver
16 17 18 |
# File 'lib/live/resolver.rb', line 16 def initialize @allowed = {} end |
Instance Attribute Details
#A map of allowed class names.(mapofallowed) ⇒ Object (readonly)
21 |
# File 'lib/live/resolver.rb', line 21 attr :allowed |
#allowed ⇒ Object (readonly)
Returns the value of attribute allowed.
21 22 23 |
# File 'lib/live/resolver.rb', line 21 def allowed @allowed end |
Class Method Details
.allow(*arguments) ⇒ Object
Creates an instance of the resolver, allowing the specified classes to be resolved.
12 13 14 |
# File 'lib/live/resolver.rb', line 12 def self.allow(*arguments) self.new.allow(*arguments).freeze end |
Instance Method Details
#allow(*arguments) ⇒ Object
Allow the specified classes to be resolved.
32 33 34 35 36 37 38 |
# File 'lib/live/resolver.rb', line 32 def allow(*arguments) arguments.each do |klass| @allowed[klass.name] = klass end return self end |
#call(id, data) ⇒ Object
Resolve a tag.
44 45 46 47 48 |
# File 'lib/live/resolver.rb', line 44 def call(id, data) if klass = @allowed[data[:class]] return klass.new(id, data) end end |
#freeze ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/live/resolver.rb', line 23 def freeze return self unless frozen? @allowed.freeze super end |