Sha256: d1e74373d7186b81117bc572071e9d416aa309fe5889989349390533d90b5b96
Contents?: true
Size: 994 Bytes
Versions: 2
Compression:
Stored size: 994 Bytes
Contents
require "mad_id/version" require "active_record" require "active_support" require "mad_id/identity_methods" require "mad_id/finder_methods" require "mad_id/railtie" if defined?(Rails) module MadID extend ActiveSupport::Concern @registry = {} class << self attr_accessor :registry def locate(id) prefix, _ = id.to_s.split('-', 2) if klass = registry[prefix] klass.find_by_mad_id(id) else nil end end def locate!(id) prefix, _ = id.to_s.split('-', 2) registry.fetch(prefix).find_by_mad_id!(id) end end included do extend(MadID::FinderMethods) 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mad_id-1.1.1 | lib/mad_id.rb |
mad_id-1.1.0 | lib/mad_id.rb |