Sha256: 7ba3769e2a9a610b0fce3fa2e1519c824d3683d91b5e9f2de6ffce7a28ae6d51
Contents?: true
Size: 737 Bytes
Versions: 3
Compression:
Stored size: 737 Bytes
Contents
# frozen_string_literal: true require 'active_record' require 'active_support' module Lite module Uxid module Record module Ulid extend ActiveSupport::Concern included do before_create :callback_generate_uxid!, if: proc { respond_to?(:uxid) } end class_methods do def find_by_uxid(uxid) find_by(uxid: uxid) end def find_by_uxid!(uxid) record = find_by_uxid(uxid) return record unless record.nil? raise ActiveRecord::RecordNotFound end end private def callback_generate_uxid! self.uxid = Lite::Uxid::Ulid.encode end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
lite-uxid-1.0.5 | lib/lite/uxid/record/ulid.rb |
lite-uxid-1.0.4 | lib/lite/uxid/record/ulid.rb |
lite-uxid-1.0.3 | lib/lite/uxid/record/ulid.rb |