Sha256: d1e71020a3eea9bc26704f34b36282890cecb37fd5ab5042dab66d5334b8b47a

Contents?: true

Size: 607 Bytes

Versions: 8

Compression:

Stored size: 607 Bytes

Contents

# frozen_string_literal: true

module EncodedId
  module Rails
    class Salt
      def initialize(klass, salt)
        @klass = klass
        @salt = salt
      end

      def generate!
        unless @klass.respond_to?(:name) && @klass.name.present?
          raise ::StandardError, "The class must have a `name` to ensure encode id uniqueness. " \
              "Please set a name on the class or override `encoded_id_salt`."
        end
        raise ::StandardError, "Encoded ID salt is invalid" if !@salt || @salt.blank? || @salt.size < 4
        "#{@klass.name}/#{@salt}"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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