Sha256: 54e37bc5beb37c13a0ea21a004778ce2920e9ec07e9458814313e189cde79e51
Contents?: true
Size: 993 Bytes
Versions: 17
Compression:
Stored size: 993 Bytes
Contents
module Steep module Services class PathAssignment attr_reader :index, :max_index, :cache def initialize(index:, max_index:) @index = index @max_index = max_index @cache = {} end def self.all new(index: 0, max_index: 1) end def =~(target_path) key = stringify(target_path) (cache[key] ||= self.class.index_for(key: key, max_index: max_index)) == index end alias === =~ def assign!(path, index) key = stringify(path) cache[key] = index self end def stringify(target_path) target = case target_path[0] when Project::Target target_path[0].name.to_s else target_path[0].to_s end path = target_path[1].to_s "#{target}::#{path}" end def self.index_for(key:, max_index:) Digest::MD5.hexdigest(key).hex % max_index end end end end
Version data entries
17 entries across 17 versions & 3 rubygems