Sha256: e0690e2496b1bce450b91848e550d6eaa029f0551f421c85518f03c3a1449a80

Contents?: true

Size: 1.07 KB

Versions: 4

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

# Index for searching value from config.yml
module Fusuma
  class Config
    # index for config.yml
    class Index
      def initialize(keys)
        @count = 0
        case keys
        when Array
          @keys = []
          @cache_key = keys.map do |key|
            key = Key.new(key) if !key.is_a? Key
            @keys << key
            key.symbol
          end.join(",")
        else
          key = Key.new(keys)
          @cache_key = key.symbol
          @keys = [key]
        end
      end

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

      attr_reader :keys, :cache_key

      # Keys in Index
      class Key
        def initialize(symbol_word, skippable: false)
          @symbol = begin
            symbol_word.to_sym
          rescue
            symbol_word
          end

          @skippable = skippable
        end

        def inspect
          if @skippable
            "#{@symbol}(skippable)"
          else
            @symbol.to_s
          end
        end

        attr_reader :symbol, :skippable
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fusuma-3.3.1 lib/fusuma/config/index.rb
fusuma-3.3.0 lib/fusuma/config/index.rb
fusuma-3.2.0 lib/fusuma/config/index.rb
fusuma-3.1.0 lib/fusuma/config/index.rb