Class: Quickdraw::Registry

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

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



7
8
9
10
11
# File 'lib/quickdraw/registry.rb', line 7

def initialize
	@registered_matchers = Quickdraw::Map.new
	@type_matchers = Quickdraw::Map.new
	@shapes = Quickdraw::Map.new
end

Instance Method Details

#expectation_for(value, matchers: nil) ⇒ Object

Given a value, find or build an expectation class that includes all the matchers for the value.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/quickdraw/registry.rb', line 22

def expectation_for(value, matchers: nil)
	if matchers
		shape_for(
			matchers + matchers_for(value)
		)
	else
		shape_for(
			matchers_for(value)
		)
	end
end

#register(matcher, *types) ⇒ Object

Register a new matcher for the given types.



14
15
16
17
18
19
# File 'lib/quickdraw/registry.rb', line 14

def register(matcher, *types)
	@registered_matchers[matcher] = types

	# We need to clear this cache because the output of `slowly_find_matchers_for` might have changed.
	@type_matchers.clear
end