Module: WithUid
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/with_uid.rb,
lib/with_uid/version.rb,
lib/with_uid/uid_generator.rb,
lib/with_uid/uid_validator.rb
Overview
Allow to generate nice uids for ActiveRecord objects
Defined Under Namespace
Modules: ClassMethods Classes: UidGenerator, UidValidator
Constant Summary collapse
- VERSION =
'0.0.1'
Class Method Summary collapse
Instance Method Summary collapse
- #generate_uid(**options, &block) ⇒ Object private
-
#skip_uid_uniqueness? ⇒ Boolean
If you are not interested in uid uniqeness redefine this method in your model.
- #uid_generator(**options, &block) ⇒ Object private
Class Method Details
.format(str) ⇒ Object
119 120 121 |
# File 'lib/with_uid.rb', line 119 def self.format(str) I18n.transliterate(str.to_s).parameterize end |
Instance Method Details
#generate_uid(**options, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
124 125 126 127 128 129 130 131 |
# File 'lib/with_uid.rb', line 124 def generate_uid(**, &block) fail LocalJumpError, 'no block given' unless block_given? return if uid.present? self.uid = uid_generator(**, &block).detect do |uid| !self.class.exists?(uid: uid) end end |
#skip_uid_uniqueness? ⇒ Boolean
If you are not interested in uid uniqeness redefine this method in your model
115 116 117 |
# File 'lib/with_uid.rb', line 115 def skip_uid_uniqueness? false end |
#uid_generator(**options, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
134 135 136 |
# File 'lib/with_uid.rb', line 134 def uid_generator(**, &block) UidGenerator.new(self, **, &block) end |