Class: TableWarnings::Registry
- Inherits:
-
Object
- Object
- TableWarnings::Registry
- Defined in:
- lib/table_warnings/registry.rb
Instance Attribute Summary collapse
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #add_warning(table, warning) ⇒ Object
- #exclusive(table) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #nonexclusive(table) ⇒ Object
- #warnings_for(table) ⇒ Object
Constructor Details
#initialize ⇒ Registry
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
#warnings ⇒ Object (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 |