Sha256: 1a639f0aeb4c6ce038334ae72412634731e84d5a7a935f8a0610719b9cd0151e
Contents?: true
Size: 1.8 KB
Versions: 3
Compression:
Stored size: 1.8 KB
Contents
# The top shelf stores all cross-thread & thread-aware state, so anything that # goes here is on its own when it comes to ensuring thread safety. module Mocktail class TopShelf def self.instance @self ||= new end def initialize @type_replacements = {} @new_registrations = {} @of_next_registrations = {} @singleton_method_registrations = {} end def type_replacement_for(type) @type_replacements[type] ||= TypeReplacement.new(type: type) end def reset_current_thread! @new_registrations[Thread.current] = [] @of_next_registrations[Thread.current] = [] @singleton_method_registrations[Thread.current] = [] end def register_new_replacement!(type) @new_registrations[Thread.current] ||= [] @new_registrations[Thread.current] |= [type] end def new_replaced?(type) @new_registrations[Thread.current] ||= [] @new_registrations[Thread.current].include?(type) end def register_of_next_replacement!(type) @of_next_registrations[Thread.current] ||= [] @of_next_registrations[Thread.current] |= [type] end def of_next_registered?(type) @of_next_registrations[Thread.current] ||= [] @of_next_registrations[Thread.current].include?(type) end def unregister_of_next_replacement!(type) @of_next_registrations[Thread.current] ||= [] @of_next_registrations[Thread.current] -= [type] end def register_singleton_method_replacement!(type) @singleton_method_registrations[Thread.current] ||= [] @singleton_method_registrations[Thread.current] |= [type] end def singleton_methods_replaced?(type) @singleton_method_registrations[Thread.current] ||= [] @singleton_method_registrations[Thread.current].include?(type) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mocktail-0.0.3 | lib/mocktail/value/top_shelf.rb |
mocktail-0.0.2 | lib/mocktail/value/top_shelf.rb |
mocktail-0.0.1 | lib/mocktail/value/top_shelf.rb |