lib/fusuma/config/index.rb in fusuma-2.5.1 vs lib/fusuma/config/index.rb in fusuma-3.0.0
- old
+ new
@@ -4,79 +4,52 @@
module Fusuma
class Config
# index for config.yml
class Index
def initialize(keys)
- @keys = case keys
+ @count = 0
+ case keys
when Array
- keys.map do |key|
- if key.is_a? Key
- key
- else
- Key.new(key)
- end
- end
+ @keys = []
+ @cache_key = keys.map do |key|
+ key = Key.new(key) if !key.is_a? Key
+ @keys << key
+ key.symbol
+ end.join(",")
else
- [Key.new(keys)]
+ key = Key.new(keys)
+ @cache_key = key.symbol
+ @keys = [key]
end
end
def inspect
@keys.map(&:inspect)
end
- attr_reader :keys
+ attr_reader :keys, :cache_key
- def cache_key
- case @keys
- when Array
- @keys.map(&:symbol).join(",")
- when Key
- @keys.symbol
- 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)
+ def initialize(symbol_word, skippable: false)
@symbol = begin
symbol_word.to_sym
rescue
symbol_word
end
@skippable = skippable
-
- @fallback = begin
- fallback.to_sym
- rescue
- fallback
- end
end
def inspect
- skip_marker = @skippable && Searcher.skip? ? "(skip)" : ""
- fallback_marker = @fallback && Searcher.fallback? ? "(fallback)" : ""
- "#{@symbol}#{skip_marker}#{fallback_marker}"
+ if @skippable
+ "#{@symbol}(skippable)"
+ else
+ "#{@symbol}"
+ end
end
- attr_reader :symbol, :skippable, :fallback
+ attr_reader :symbol, :skippable
end
end
end
end