class method self.locate

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

Signature

self.locate(gid, options = {})

Takes either a GlobalID or a string that can be turned into a GlobalID

Options:

  • :includes - A Symbol, Array, Hash or combination of them. The same structure you would pass into a includes method of Active Record. If present, locate will load all the relationships specified here. See guides.rubyonrails.org/active_record_querying.html#eager-loading-associations.

  • :only - A class, module or Array of classes and/or modules that are allowed to be located. Passing one or more classes limits instances of returned classes to those classes or their subclasses. Passing one or more modules in limits instances of returned classes to those including that module. If no classes or modules match, nil is returned.

Parameters

gid req
options opt = {}
Source
# File lib/global_id/locator.rb, line 23
      def locate(gid, options = {})
        gid = GlobalID.parse(gid)

        return unless gid && find_allowed?(gid.model_class, options[:only])

        locator = locator_for(gid)

        if locator.method(:locate).arity == 1
          GlobalID.deprecator.warn "It seems your locator is defining the `locate` method only with one argument. Please make sure your locator is receiving the options argument as well, like `locate(gid, options = {})`."
          locator.locate(gid)
        else
          locator.locate(gid, options.except(:only))
        end
      end

Defined in lib/global_id/locator.rb line 23 · View on GitHub · Improve this page · Find usages on GitHub

Defined in GlobalID::Locator

Type at least 2 characters to search.

↑↓ navigate · open · esc close