module MadID

Constants

VERSION

Attributes

registry[RW]

Public Class Methods

identify_with(value, options = {}) click to toggle source
# File lib/mad_id.rb, line 34
def self.identify_with(value, options = {})
  self.mad_id_column = options[:column] || 'identifier'
  @identifier = value
  MadID.registry[value.to_s] = self
  self.send(:include, MadID::IdentityMethods)
  self.send(:include, MadID::IdentityMethods::UrlMethods) unless options[:to_param] == false # include by default
end
locate(id) click to toggle source
# File lib/mad_id.rb, line 17
def locate(id)
  prefix, _ = id.to_s.split('-', 2)
  if klass = registry[prefix]
    klass.find_by_mad_id(id)
  else
    nil
  end
end
locate!(id) click to toggle source
# File lib/mad_id.rb, line 26
def locate!(id)
  prefix, _ = id.to_s.split('-', 2)
  registry.fetch(prefix).find_by_mad_id!(id)
end