Sha256: 66f6275960650094b6bfefbfab615ad7c0b606d7e436c9174fd0f08436a9c9f1

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 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(",").to_sym
        else
          key = Key.new(keys)
          @cache_key = key.symbol
          @keys = [key]
        end
      end

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

      def ==(other)
        return false unless other.is_a? Index

        cache_key == other.cache_key
      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 to_s
          if @skippable
            "#{@symbol}(skippable)"
          else
            @symbol.to_s
          end
        end

        attr_reader :symbol, :skippable
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fusuma-3.7.0 lib/fusuma/config/index.rb
fusuma-3.6.2 lib/fusuma/config/index.rb
fusuma-3.6.1 lib/fusuma/config/index.rb
fusuma-3.6.0 lib/fusuma/config/index.rb
fusuma-3.5.0 lib/fusuma/config/index.rb
fusuma-3.4.0 lib/fusuma/config/index.rb