class method
self.use
Ruby on Rails 1.1.0
Last seen in v1.3.0Signature
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
-
appreq -
locatoropt = nil -
locator_blockblock
Source
# File lib/global_id/locator.rb, line 98
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 98
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in GlobalID::Locator