class method self.use

Ruby on Rails 1.0.1

Last seen in v1.3.0

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

Signature

self.use(app, locator = nil, &locator_block)

Tie a locator to an app. Useful when different apps collaborate and reference each others’ Global IDs.

The locator can be either a block or a class.

Using a block:

GlobalID::Locator.use :foo do |gid|
  FooRemote.const_get(gid.model_name).find(gid.model_id)
end

Using a class:

GlobalID::Locator.use :bar, BarLocator.new

class BarLocator
  def locate(gid)
    @search_client.search name: gid.model_name, id: gid.model_id
  end
end

Parameters

app req
locator opt = nil
locator_block block
Source
# File lib/global_id/locator.rb, line 99
      def use(app, locator = nil, &locator_block)
        raise ArgumentError, 'No locator provided. Pass a block or an object that responds to #locate.' unless locator || block_given?

        URI::GID.validate_app(app)

        @locators[normalize_app(app)] = locator || BlockLocator.new(locator_block)
      end

Defined in lib/global_id/locator.rb line 99 · 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