-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'delegate' | ||
require 'globalid' | ||
|
||
module Hyperclient | ||
module GlobalId | ||
class Locator | ||
def locate(gid) | ||
Hyperclient | ||
.lookup_entry_point(gid.params['endpoint']) | ||
.public_send(gid.params['key'], gid.params.except('endpoint', 'key')) | ||
end | ||
end | ||
|
||
class Serializable < SimpleDelegator | ||
def id | ||
_url | ||
end | ||
end | ||
|
||
private_constant :Serializable | ||
|
||
def self.app_name | ||
"#{GlobalID.app}-hyperclient" | ||
end | ||
|
||
def self.setup! | ||
::Hyperclient::Link.include ::GlobalID::Identification | ||
::Hyperclient::Link.prepend ::Hyperclient::GlobalId | ||
|
||
::GlobalID::Locator.use app_name, ::Hyperclient::GlobalId::Locator.new | ||
end | ||
|
||
def to_global_id(options = {}) | ||
GlobalID.create(Serializable.new(self), default_global_id_options.merge(options)) | ||
end | ||
alias to_gid to_global_id | ||
|
||
def to_signed_global_id(options = {}) | ||
SignedGlobalID.create(Serializable.new(self), default_global_id_options.merge(options)) | ||
end | ||
alias to_sgid to_signed_global_id | ||
|
||
private | ||
|
||
def default_global_id_options | ||
{ | ||
app: ::Hyperclient::GlobalId.app_name, | ||
endpoint: @entry_point._url, | ||
key: @key, | ||
**@uri_variables || {}, | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Hyperclient | ||
class Railtie < ::Rails::Railtie #:nodoc: | ||
initializer 'hyperclient.client.attach_log_subscriber' do | ||
ActiveSupport.on_load(:active_job) do | ||
require 'hyperclient/global_id' | ||
|
||
::Hyperclient::GlobalId.setup! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters