Class: Coupdoeil::Popover::Registry

Inherits:
Object
  • Object
show all
Defined in:
app/models/coupdoeil/popover/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

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

#registryObject (readonly)

Returns the value of attribute registry.



6
7
8
# File 'app/models/coupdoeil/popover/registry.rb', line 6

def registry
  @registry
end

#semaphoreObject (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] }