Sha256: 452ca41ec01e381dbffaf88d597d102c8c52d96c5e1ffcf69684c1d9a0b2fde2

Contents?: true

Size: 826 Bytes

Versions: 1

Compression:

Stored size: 826 Bytes

Contents

# frozen_string_literal: true

module EncodedId
  module Rails
    class Coder
      def initialize(salt:, id_length:, character_group_size:, separator:, alphabet:)
        @salt = salt
        @id_length = id_length
        @character_group_size = character_group_size
        @separator = separator
        @alphabet = alphabet
      end

      def encode(id)
        coder.encode(id)
      end

      def decode(encoded_id)
        coder.decode(encoded_id)
      rescue EncodedId::EncodedIdFormatError, EncodedId::InvalidInputError
        nil
      end

      private

      def coder
        ::EncodedId::ReversibleId.new(
          salt: @salt,
          length: @id_length,
          split_at: @character_group_size,
          split_with: @separator,
          alphabet: @alphabet
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
encoded_id-rails-1.0.0.beta3 lib/encoded_id/rails/coder.rb