Sha256: 5976204df48748980d2ef7ac4647f403577d91e68d84c1df8f042ca5909da939

Contents?: true

Size: 552 Bytes

Versions: 3

Compression:

Stored size: 552 Bytes

Contents

# frozen_string_literal: true

require "cgi"

module EncodedId
  module Rails
    class AnnotatedId
      def initialize(annotation:, id_part:, separator: "_")
        @annotation = annotation
        @id_part = id_part
        @separator = separator
      end

      def annotated_id
        unless @id_part.present? && @annotation.present?
          raise ::StandardError, "The model does not provide a valid ID and/or annotation"
        end
        "#{@annotation.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/annotated_id.rb
encoded_id-rails-1.0.0.beta2 lib/encoded_id/rails/annotated_id.rb
encoded_id-rails-1.0.0.beta1 lib/encoded_id/rails/annotated_id.rb