Module: EncodedId::Rails::EncoderMethods
- Defined in:
- lib/encoded_id/rails/encoder_methods.rb
Instance Method Summary collapse
- #decode_encoded_id(slugged_encoded_id, options = {}) ⇒ Object
- #encode_encoded_id(ids, options = {}) ⇒ Object
- #encoded_id_coder(options = {}) ⇒ Object
- #encoded_id_parser(slugged_encoded_id) ⇒ Object
-
#encoded_id_salt ⇒ Object
This can be overridden in the model to provide a custom salt.
Instance Method Details
#decode_encoded_id(slugged_encoded_id, options = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/encoded_id/rails/encoder_methods.rb', line 11 def decode_encoded_id(slugged_encoded_id, = {}) return if slugged_encoded_id.blank? encoded_id = encoded_id_parser(slugged_encoded_id).id return if !encoded_id || encoded_id.blank? encoded_id_coder().decode(encoded_id) end |
#encode_encoded_id(ids, options = {}) ⇒ Object
6 7 8 9 |
# File 'lib/encoded_id/rails/encoder_methods.rb', line 6 def encode_encoded_id(ids, = {}) raise StandardError, "You must pass an ID or array of IDs" if ids.blank? encoded_id_coder().encode(ids) end |
#encoded_id_coder(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/encoded_id/rails/encoder_methods.rb', line 28 def encoded_id_coder( = {}) config = EncodedId::Rails.configuration EncodedId::Rails::Coder.new( salt: [:salt] || encoded_id_salt, id_length: [:id_length] || config.id_length, character_group_size: [:character_group_size] || config.character_group_size, alphabet: [:alphabet] || config.alphabet, separator: [:separator] || config.group_separator ) end |
#encoded_id_parser(slugged_encoded_id) ⇒ Object
24 25 26 |
# File 'lib/encoded_id/rails/encoder_methods.rb', line 24 def encoded_id_parser(slugged_encoded_id) SluggedIdParser.new(slugged_encoded_id, separator: EncodedId::Rails.configuration.slugged_id_separator) end |