Sha256: f67becb5a9d1a7cae2517de692253eeb9deffacf8656e5b8f96ba9c641e251a2

Contents?: true

Size: 1.22 KB

Versions: 9

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Primer
  module Octicon
    # :nodoc:
    class Cache
      LOOKUP = {} # rubocop:disable Style/MutableConstant
      # Preload the top 20 used icons.
      PRELOADED_ICONS = [:alert, :check, :"chevron-down", :paste, :clock, :"dot-fill", :info, :"kebab-horizontal", :link, :lock, :mail, :pencil, :plus, :question, :repo, :search, :"shield-lock", :star, :trash, :x].freeze

      class << self
        def get_key(**kwargs)
          correct_key_args?(**kwargs)
          kwargs.hash
        end

        def read(key)
          LOOKUP[key]
        end

        # Cache size limit.
        def limit
          500
        end

        def set(key, value)
          LOOKUP[key] = value

          # Remove first item when the cache is too large.
          LOOKUP.shift if LOOKUP.size > limit
        end

        def clear!
          LOOKUP.clear
        end

        def preload!
          PRELOADED_ICONS.each { |icon| Primer::OcticonComponent.new(icon: icon) }
        end

        private

        def correct_key_args?(symbol:, size:, width: nil, height: nil)
          # This method does nothing but will raise an ArgumentError if the
          # wrong args are passed.
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
primer_view_components-0.0.63 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.62 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.61 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.60 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.59 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.58 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.57 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.56 app/lib/primer/octicon/cache.rb
primer_view_components-0.0.55 app/lib/primer/octicon/cache.rb