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
Returns a new instance of Resolver.
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 |
#allowed ⇒ Object (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 |
#freeze ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/live/resolver.rb', line 40 def freeze return self unless frozen? @allowed.freeze super end |