I have an isolated Rails Engine: Admin
.
In that Engine I create Sites
through a GUI.
in Engine:
module Admin
class Site < ActiveRecord::Base
end
end
In main app I inherit from the engine's Site
in order to use it as a constant at the root level:
class Site < Admin::Site
end
I do this because it feels wrong to couple the Admin::Site
in models, controllers and tests of the main app. But I guess there's some downsides to this approach and I also guess one could argue that the coupling is the same.
How can I delegate this in a better way than inheritance?
OR
Should I restructure my code and maybe put the Site
class in a gem that both the main app and the Engine can use? What I would really like is an interface to the engine's class to reduce the entry points, and thus the coupling.
Sidenote, I have a total of 3-4 of these classes that resides in the engine but is used in the main app.
EDIT:
Maybe I should just wrap it like this:
class Site
def initialize(args = {})
@klass = Admin::Site.new(args)
end
def method_missing(method_name, *args, &block)
@klass.send(method_name, *args, &block)
end
end
Of course, then I could also narrow the interface of Site
to only include what I need from Admin::Site
in the main app.