lib/fusuma/config/searcher.rb in fusuma-3.4.0 vs lib/fusuma/config/searcher.rb in fusuma-3.5.0
- old
+ new
@@ -79,21 +79,23 @@
attr_reader :context
# Search with context from load_streamed Config
# @param context [Hash]
# @return [Object]
- def with_context(context, &block)
- @context = context || {}
+ def with_context(context = {}, &block)
+ before = @context
+ @context = context
result = block.call
- @context = {}
+ ensure # NOTE: ensure is called even if return in block
+ @context = before
result
end
- CONEXT_SEARCH_ORDER = [:no_context, :complete_match_context, :partial_match_context]
+ CONTEXT_SEARCH_ORDER = [:no_context, :complete_match_context, :partial_match_context]
# Return a matching context from config
# @params request_context [Hash]
# @return [Hash]
- def find_context(request_context, fallbacks = CONEXT_SEARCH_ORDER, &block)
+ def find_context(request_context, fallbacks = CONTEXT_SEARCH_ORDER, &block)
# Search in blocks in the following order.
# 1. primary context(no context)
# 2. complete match config[:context] == request_context
# 3. partial match config[:context] =~ request_context
# no_context?(&block) ||