Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34
Add better support for GlobalId and active job#150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -7,16 +7,23 @@ | ||
| require 'hyperclient/resource' | ||
| require 'hyperclient/resource_collection' | ||
| require 'hyperclient/version' | ||
| require 'hyperclient/railtie' if defined?(Rails) | ||
| # Public: Hyperclient namespace. | ||
| # | ||
| module Hyperclient | ||
| URL_TO_ENDPOINT_MAPPING = { } | ||
| # Public: Convenience method to create new EntryPoints. | ||
| # | ||
| # url - A String with the url of the API. | ||
| # | ||
| # Returns a Hyperclient::EntryPoint | ||
| def self.new(url, &block) | ||
| Hyperclient::EntryPoint.new(url, &block) | ||
| URL_TO_ENDPOINT_MAPPING[url] = Hyperclient::EntryPoint.new(url, &block) | ||
| ||
| end | ||
| def self.lookup_entry_point(uri) | ||
| URL_TO_ENDPOINT_MAPPING[uri] || raise(ArgumentError, "Entry point not registered for #{uri}") | ||
| end | ||
| end | ||
| 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('app', '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 = {}) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: I suggest using the more modern | ||
| 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 | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Don't forget to configure your editor to add a newline at the end of the file :) | ||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a constant, shouldn't be
CAPS.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reference seems constant, as it's the object itself that will be mutated, right?