Class: Dumpling::TestRegistry
- Defined in:
- lib/dumpling/test_registry.rb
Instance Method Summary collapse
- #get(id) ⇒ Object
- #has?(id, include_child: true) ⇒ Boolean
-
#initialize(child_registry = Registry.new) ⇒ TestRegistry
constructor
A new instance of TestRegistry.
- #initialize_dup(original) ⇒ Object
- #keys(include_child: true) ⇒ Object
- #mock(id, value) ⇒ Object
- #set(id, value) ⇒ Object
Constructor Details
#initialize(child_registry = Registry.new) ⇒ TestRegistry
Returns a new instance of TestRegistry.
3 4 5 6 7 |
# File 'lib/dumpling/test_registry.rb', line 3 def initialize(child_registry = Registry.new) @child_registry = child_registry @all_keys = child_registry.keys.dup super() end |
Instance Method Details
#get(id) ⇒ Object
20 21 22 |
# File 'lib/dumpling/test_registry.rb', line 20 def get(id) has?(id, include_child: false) ? super : @child_registry.get(id) end |
#has?(id, include_child: true) ⇒ Boolean
24 25 26 |
# File 'lib/dumpling/test_registry.rb', line 24 def has?(id, include_child: true) keys(include_child: include_child).include?(id) end |
#initialize_dup(original) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/dumpling/test_registry.rb', line 32 def initialize_dup(original) super.tap do @child_registry = original.child_registry.dup @all_keys = original.all_keys.dup @keys = original.keys(include_child: false).dup end end |
#keys(include_child: true) ⇒ Object
28 29 30 |
# File 'lib/dumpling/test_registry.rb', line 28 def keys(include_child: true) include_child ? @all_keys : @keys end |
#mock(id, value) ⇒ Object
9 10 11 12 13 |
# File 'lib/dumpling/test_registry.rb', line 9 def mock(id, value) @keys << id @all_keys << id @data[id] = value end |
#set(id, value) ⇒ Object
15 16 17 18 |
# File 'lib/dumpling/test_registry.rb', line 15 def set(id, value) @all_keys << id @child_registry.set(id, value) end |