Eric Gross
06/05/2023, 11:03 PMclass_eval
that i suspect i can replace with a cleaner prepended situation, but i'm not sure how ... my current code is
Spree::Base.class_eval do
before_create :associate_tenant
class TenantNotFound < StandardError; end
def associate_tenant
return logger.warn("Ingoring setting tenant") if RLS.disabled?
raise(TenantNotFound, "RLS.current_tenant is not set") unless RLS.current_tenant
self.tenant_id = RLS.current_tenant_id
<http://logger.info|logger.info>("Set thread for #{self.class.name}")
end
end
is there an obvious way to replace this evaluated callback creation with one that would prepend the callback instead?Chris Todorov
06/05/2023, 11:18 PMApplicationRecord
class?Chris Todorov
06/05/2023, 11:23 PMSpree::Base
class like you are doing.Chris Todorov
06/05/2023, 11:25 PMclass_eval
.
Something like
# 'app/models/my_app/base_decorator.rb'
module MyApp::BaseDecorator
def self.prepended(base)
base.before_create :associate_tenant
end
# all the other stuff you have ...
Spree::Base.prepend(self)
end
Chris Todorov
06/05/2023, 11:27 PMprepend
Jared Norman
Chris Todorov
06/05/2023, 11:44 PMApplicationRecord
right? https://github.com/solidusio/solidus/pull/3476Chris Todorov
06/05/2023, 11:45 PMEric Gross
06/06/2023, 3:45 PM