Sha256: 879a0a121664187009f44cc9e85de0a963e28dc232d64ecfd0409f2f42795687

Contents?: true

Size: 719 Bytes

Versions: 2

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

#
# Copyright (c) 2019-present, Blue Marble Payroll, LLC
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

module Airspace
  # This class understands how to build keys and subkeys for storing data inside Redis.
  class Key
    SEPARATOR_CHAR = ':'

    private_constant :SEPARATOR_CHAR

    attr_reader :id, :prefix

    def initialize(id, prefix: '')
      @id     = id.to_s
      @prefix = prefix.to_s
    end

    def root
      return id if prefix.empty?

      [prefix, id].join(SEPARATOR_CHAR)
    end
    alias to_s root

    def chunk(index)
      [root, index].join(SEPARATOR_CHAR)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
airspace-1.0.1 lib/airspace/key.rb
airspace-1.0.0 lib/airspace/key.rb