Class: TableWarnings::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/table_warnings/registry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



5
6
7
8
# File 'lib/table_warnings/registry.rb', line 5

def initialize
  @warnings = {}
  @warnings_mutex = Mutex.new
end

Instance Attribute Details

#warningsObject (readonly)

Returns the value of attribute warnings.



3
4
5
# File 'lib/table_warnings/registry.rb', line 3

def warnings
  @warnings
end

Instance Method Details

#add_warning(table, warning) ⇒ Object



10
11
12
13
14
15
# File 'lib/table_warnings/registry.rb', line 10

def add_warning(table, warning)
  @warnings_mutex.synchronize do
    warnings[table.to_s] ||= []
    warnings[table.to_s] << warning
  end
end

#exclusive(table) ⇒ Object



26
27
28
29
30
# File 'lib/table_warnings/registry.rb', line 26

def exclusive(table)
  warnings_for(table).select do |warning|
    warning.respond_to? :exclusives
  end
end

#nonexclusive(table) ⇒ Object



32
33
34
35
36
# File 'lib/table_warnings/registry.rb', line 32

def nonexclusive(table)
  warnings_for(table).reject do |warning|
    warning.respond_to? :exclusives
  end
end

#warnings_for(table) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/table_warnings/registry.rb', line 17

def warnings_for(table)
  k = table.to_s
  if warnings.has_key?(k)
    warnings[k].dup
  else
    []
  end
end