lib/fusuma/config/index.rb in fusuma-2.0.0.pre vs lib/fusuma/config/index.rb in fusuma-2.0.0.pre2

- old
+ new

@@ -17,10 +17,15 @@ end else [Key.new(keys)] end end + + def inspect + @keys.map(&:inspect) + end + attr_reader :keys def cache_key case @keys when Array @@ -30,26 +35,47 @@ else raise 'invalid keys' end end + # @return [Index] + def with_context + keys = @keys.map do |key| + next if Searcher.skip? && key.skippable + + if Searcher.fallback? && key.fallback + key.fallback + else + key + end + end + self.class.new(keys.compact) + end + # Keys in Index class Key def initialize(symbol_word, skippable: false, fallback: nil) @symbol = begin - symbol_word.to_sym - rescue StandardError - symbol_word - end + symbol_word.to_sym + rescue StandardError + symbol_word + end @skippable = skippable @fallback = begin - fallback.to_sym - rescue StandardError - fallback - end + fallback.to_sym + rescue StandardError + fallback + end end + + def inspect + skip_marker = @skippable && Searcher.skip? ? '(skip)' : '' + fallback_marker = @fallback && Searcher.fallback? ? '(fallback)' : '' + "#{@symbol}#{skip_marker}#{fallback_marker}" + end + attr_reader :symbol, :skippable, :fallback end end end end