Sha256: b740fb9837f3c3f9219ae5989bfd14de486c37c9f2d7e1a1a58fd009001824ca

Contents?: true

Size: 537 Bytes

Versions: 3

Compression:

Stored size: 537 Bytes

Contents

# frozen_string_literal: true

require "cgi"

module EncodedId
  module Rails
    class SluggedId
      def initialize(slug_part:, id_part:, separator: "--")
        @slug_part = slug_part
        @id_part = id_part
        @separator = separator
      end

      def slugged_id
        unless @id_part.present? && @slug_part.present?
          raise ::StandardError, "The model does not return a valid ID and/or slug"
        end
        "#{@slug_part.to_s.parameterize}#{CGI.escape(@separator)}#{@id_part}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
encoded_id-rails-1.0.0.beta3 lib/encoded_id/rails/slugged_id.rb
encoded_id-rails-1.0.0.beta2 lib/encoded_id/rails/slugged_id.rb
encoded_id-rails-1.0.0.beta1 lib/encoded_id/rails/slugged_id.rb