Sha256: 3e3dd1bad23798e84f405447a3d172acd79c9bddcc275d1634fb124689e5725b

Contents?: true

Size: 611 Bytes

Versions: 1

Compression:

Stored size: 611 Bytes

Contents

# frozen_string_literal: true

module ActiveUxid
  module Record
    module Hash
      extend ActiveSupport::Concern

      included do
        after_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) }

        def self.find_by_uxid(uxid)
          iden = ActiveUxid::Hash.decode(uxid)
          find(iden)
        end
      end

      def uxid_to_id
        return unless respond_to?(:uxid)

        ActiveUxid::Hash.decode(uxid)
      end

      private

      def callback_generate_uxid!
        hash = ActiveUxid::Hash.encode(id)
        update_column(:uxid, hash)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_uxid-5.1.0 lib/active_uxid/record/hash.rb