Module: PrefixedIds
- Defined in:
- lib/prefixed_ids.rb,
lib/prefixed_ids/engine.rb,
lib/prefixed_ids/version.rb,
lib/prefixed_ids/prefix_id.rb
Defined Under Namespace
Modules: Attribute, Exists, Finder, Rails, ToParam Classes: Engine, Error, PrefixId
Constant Summary collapse
- VERSION =
"1.8.1"
Class Method Summary collapse
- .find(prefix_id) ⇒ Object
-
.split_id(prefix_id, delimiter = PrefixedIds.delimiter) ⇒ Object
Splits a prefixed ID into its prefix and ID.
Class Method Details
.find(prefix_id) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/prefixed_ids.rb', line 18 def self.find(prefix_id) prefix, _ = split_id(prefix_id) models.fetch(prefix).find_by_prefix_id(prefix_id) rescue KeyError raise Error, "Unable to find model with prefix `#{prefix}`. Available prefixes are: #{models.keys.join(", ")}" end |
.split_id(prefix_id, delimiter = PrefixedIds.delimiter) ⇒ Object
Splits a prefixed ID into its prefix and ID
26 27 28 29 |
# File 'lib/prefixed_ids.rb', line 26 def self.split_id(prefix_id, delimiter = PrefixedIds.delimiter) prefix, _, id = prefix_id.to_s.rpartition(delimiter) [prefix, id] end |