Sha256: d475e7f43d27c51e1ee01b1babe6294d1a42f0508fb16cfc04807a4e36197a8a

Contents?: true

Size: 610 Bytes

Versions: 16

Compression:

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

16 entries across 16 versions & 1 rubygems

Version Path
active_uxid-5.0.2 lib/active_uxid/record/hash.rb
active_uxid-5.0.1 lib/active_uxid/record/hash.rb
active_uxid-5.0.0 lib/active_uxid/record/hash.rb
active_uxid-1.0.13 lib/active_uxid/record/hash.rb
active_uxid-1.0.12 lib/active_uxid/record/hash.rb
active_uxid-1.0.11 lib/active_uxid/record/hash.rb
active_uxid-1.0.10 lib/active_uxid/record/hash.rb
active_uxid-1.0.9 lib/active_uxid/record/hash.rb
active_uxid-1.0.8 lib/active_uxid/record/hash.rb
active_uxid-1.0.7 lib/active_uxid/record/hash.rb
active_uxid-1.0.6 lib/active_uxid/record/hash.rb
active_uxid-1.0.5 lib/active_uxid/record/hash.rb
active_uxid-1.0.4 lib/active_uxid/record/hash.rb
active_uxid-1.0.3 lib/active_uxid/record/hash.rb
active_uxid-1.0.2 lib/active_uxid/record/hash.rb
active_uxid-1.0.1 lib/active_uxid/record/hash.rb