Class: Coupdoeil::Popover::Registry
- Inherits:
-
Object
- Object
- Coupdoeil::Popover::Registry
- Defined in:
- app/models/coupdoeil/popover/registry.rb
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#semaphore ⇒ Object
readonly
Returns the value of attribute semaphore.
Instance Method Summary collapse
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #lookup(type) ⇒ Object
- #lookup_or_register(type) ⇒ Object
- #register(type, klass) ⇒ Object
- #safe_lookup(type) ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
8 9 10 11 |
# File 'app/models/coupdoeil/popover/registry.rb', line 8 def initialize @semaphore = Mutex.new @registry = Hash.new end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
6 7 8 |
# File 'app/models/coupdoeil/popover/registry.rb', line 6 def registry @registry end |
#semaphore ⇒ Object (readonly)
Returns the value of attribute semaphore.
6 7 8 |
# File 'app/models/coupdoeil/popover/registry.rb', line 6 def semaphore @semaphore end |
Instance Method Details
#lookup(type) ⇒ Object
14 |
# File 'app/models/coupdoeil/popover/registry.rb', line 14 def lookup(type) = @semaphore.synchronize {@registry.fetch(type) } |
#lookup_or_register(type) ⇒ Object
17 18 19 20 21 22 |
# File 'app/models/coupdoeil/popover/registry.rb', line 17 def lookup_or_register(type) safe_lookup(type) || begin register(type, (type.classify + "Popover").constantize) end end |
#register(type, klass) ⇒ Object
13 |
# File 'app/models/coupdoeil/popover/registry.rb', line 13 def register(type, klass) = @semaphore.synchronize { @registry[type] = klass } |
#safe_lookup(type) ⇒ Object
15 |
# File 'app/models/coupdoeil/popover/registry.rb', line 15 def safe_lookup(type) = @semaphore.synchronize {@registry[type] } |