Class: TestBench::Registry
- Inherits:
-
Object
- Object
- TestBench::Registry
- Defined in:
- lib/test_bench/registry.rb
Instance Attribute Summary collapse
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Class Method Summary collapse
Instance Method Summary collapse
- #get(binding) ⇒ Object
-
#initialize(factory) ⇒ Registry
constructor
A new instance of Registry.
- #key(binding) ⇒ Object
- #set(binding, value) ⇒ Object
- #table ⇒ Object
Constructor Details
#initialize(factory) ⇒ Registry
Returns a new instance of Registry.
5 6 7 |
# File 'lib/test_bench/registry.rb', line 5 def initialize factory @factory = factory end |
Instance Attribute Details
#factory ⇒ Object (readonly)
Returns the value of attribute factory.
3 4 5 |
# File 'lib/test_bench/registry.rb', line 3 def factory @factory end |
Class Method Details
.build(&block) ⇒ Object
9 10 11 12 |
# File 'lib/test_bench/registry.rb', line 9 def self.build &block factory = block new factory end |
Instance Method Details
#get(binding) ⇒ Object
18 19 20 21 |
# File 'lib/test_bench/registry.rb', line 18 def get binding key = self.key binding table[key] ||= factory.() end |
#key(binding) ⇒ Object
14 15 16 |
# File 'lib/test_bench/registry.rb', line 14 def key binding binding.receiver.object_id end |
#set(binding, value) ⇒ Object
23 24 25 26 |
# File 'lib/test_bench/registry.rb', line 23 def set binding, value key = self.key binding table[key] = value end |
#table ⇒ Object
28 29 30 |
# File 'lib/test_bench/registry.rb', line 28 def table @table ||= {} end |