module Identification

Ruby on Rails 1.3.0

Last seen in v1.3.0

Available in: v1.0.1 v1.1.0 v1.2.1 v1.3.0

Mix GlobalID::Identification into any model with a ‘#find(id)` class method. Support is automatically included in Active Record.

class Person
  include ActiveModel::Model
  include GlobalID::Identification

  attr_accessor :id

  def self.find(id)
    new id: id
  end

  def ==(other)
    id == other.try(:id)
  end
end

person_gid = Person.find(1).to_global_id
# => #<GlobalID ...
person_gid.uri
# => #<URI ...
person_gid.to_s
# => "gid://app/Person/1"
GlobalID::Locator.locate person_gid
# => #<Person:0x007fae94bf6298 @id="1">

Methods (defined here)

Type at least 2 characters to search.

↑↓ navigate · open · esc close