Class: Fusuma::Config::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/config/index.rb

Overview

index for config.yml

Defined Under Namespace

Classes: Key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ Index

Returns a new instance of Index.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fusuma/config/index.rb', line 8

def initialize(keys)
  @keys = case keys
          when Array
            keys.map do |key|
              if key.is_a? Key
                key
              else
                Key.new(key)
              end
            end
          else
            [Key.new(keys)]
          end
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



27
28
29
# File 'lib/fusuma/config/index.rb', line 27

def keys
  @keys
end

Instance Method Details

#cache_keyObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/fusuma/config/index.rb', line 29

def cache_key
  case @keys
  when Array
    @keys.map(&:symbol).join(',')
  when Key
    @keys.symbol
  else
    raise 'invalid keys'
  end
end

#inspectObject



23
24
25
# File 'lib/fusuma/config/index.rb', line 23

def inspect
  @keys.map(&:inspect)
end

#with_contextIndex

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fusuma/config/index.rb', line 41

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