Sha256: 76ea4984fa87b76774680ed3f4649a07b35dce57e70e97edf7bf8e0eba1e1bf6

Contents?: true

Size: 796 Bytes

Versions: 7

Compression:

Stored size: 796 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
        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

7 entries across 7 versions & 1 rubygems

Version Path
encoded_id-rails-1.0.0.beta2 lib/encoded_id/rails/coder.rb
encoded_id-rails-1.0.0.beta1 lib/encoded_id/rails/coder.rb
encoded_id-rails-0.6.2 lib/encoded_id/rails/coder.rb
encoded_id-rails-0.6.1 lib/encoded_id/rails/coder.rb
encoded_id-rails-0.6.0 lib/encoded_id/rails/coder.rb
encoded_id-rails-0.5.0 lib/encoded_id/rails/coder.rb
encoded_id-rails-0.4.0 lib/encoded_id/rails/coder.rb