Skip to content

global_id support #128

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def service_name; Ros::Sdk.configured_services[Settings.service.name] end
end

included do
def gid
@gid ||= GlobalID.create(self, app: Settings.service.name)
end

def current_tenant; self.class.current_tenant end

after_commit :stream_cloud_event, if: -> { Settings.event_logging.enabled }
Expand Down
12 changes: 12 additions & 0 deletions lib/core/app/models/service_locator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module ServiceLocator
module_function

def locate(gid)
gid = GlobalID.parse(gid)
return unless gid

GlobalID::Locator.send(:locator_for, gid).locate gid
end
end
2 changes: 1 addition & 1 deletion lib/core/app/resources/ros/application_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApplicationResource < JSONAPI::Resource
include Ros::UrlBuilder
include AssociationResource::ResourceHelper
abstract
attributes :urn, :created_at, :updated_at
attributes :urn, :created_at, :updated_at, :gid

def urn; @model.to_urn end

Expand Down
12 changes: 11 additions & 1 deletion lib/core/lib/ros/core/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class Engine < ::Rails::Engine
allow do
origins Settings.cors.origins
resource Settings.cors.resource, headers: :any,
methods: %i[get post delete put patch options head]
methods: %i[get post delete put patch options head]
end
end
end
Expand All @@ -217,6 +217,16 @@ class Engine < ::Rails::Engine
FactoryBot.definition_file_paths.prepend(Ros.spec_root.join('factories')) if defined?(FactoryBot) && !Rails.env.production?
end

initializer 'ros_core.configure_global_id', after: 'ros.core.configure_platform_services_connections' do
Ros::Sdk.configured_services.each do |name, connection|
next if Settings.service.name == name

GlobalID::Locator.use name do |gid|
connection.const_get(gid.model_name).find(gid.model_id)
end
end
end

config.after_initialize do
require_relative 'console' unless Rails.const_defined?('Server')
if Settings.event_logging.enabled
Expand Down