class GlobalID
def self.deprecator # :nodoc:
def self.deprecator # :nodoc: @deprecator ||= ActiveSupport::Deprecation.new("2.1", "GlobalID") end
def self.eager_load!
def self.eager_load! super require 'global_id/signed_global_id' end
def ==(other)
def ==(other) other.is_a?(GlobalID) && @uri == other.uri end
def app=(app)
def app=(app) @app = URI::GID.validate_app(app) end
def as_json(*)
def as_json(*) to_s end
def create(model, options = {})
def create(model, options = {}) if app = options.fetch(:app) { GlobalID.app } params = options.except(:app, :verifier, :for) new URI::GID.create(app, model, params), options else raise ArgumentError, 'An app is required to create a GlobalID. ' \ 'Pass the :app option or set the default GlobalID.app.' end end
def find(gid, options = {})
def find(gid, options = {}) parse(gid, options).try(:find, options) end
def find(options = {})
def find(options = {}) Locator.locate self, options end
def hash
def hash self.class.hash | @uri.hash end
def initialize(gid, options = {})
def initialize(gid, options = {}) @uri = gid.is_a?(URI::GID) ? gid : URI::GID.parse(gid) end
def model_class
def model_class @model_class ||= begin model = model_name.constantize if model <= GlobalID raise ArgumentError, "GlobalID and SignedGlobalID cannot be used as model_class." end model end end
def parse(gid, options = {})
def parse(gid, options = {}) gid.is_a?(self) ? gid : new(gid, options) rescue URI::Error parse_encoded_gid(gid, options) end
def parse_encoded_gid(gid, options)
def parse_encoded_gid(gid, options) new(Base64.urlsafe_decode64(gid), options) rescue nil end
def to_param
def to_param Base64.urlsafe_encode64(to_s, padding: false) end