module SolidusSupport::EngineExtensions::ClassMethods
Public Instance Methods
activate()
click to toggle source
# File lib/solidus_support/engine_extensions.rb, line 25 def activate load_solidus_decorators_from(solidus_decorators_root) load_solidus_subscribers_from(solidus_subscribers_root) end
load_solidus_decorators_from(path)
click to toggle source
Loads decorator files.
This is needed since they are never explicitly referenced in the application code and won't be loaded by default. We need them to be executed regardless in order to decorate existing classes.
# File lib/solidus_support/engine_extensions.rb, line 53 def load_solidus_decorators_from(path) path.glob('**/*.rb') do |decorator_path| require_dependency(decorator_path) end end
load_solidus_subscribers_from(path)
click to toggle source
Loads Solidus event subscriber files.
This allows to add event subscribers to extensions without explicitly subscribing them, similarly to what happens in Solidus core.
# File lib/solidus_support/engine_extensions.rb, line 34 def load_solidus_subscribers_from(path) if defined? Spree::Event path.glob("**/*_subscriber.rb") do |subscriber_path| require_dependency(subscriber_path) end if Spree::Event.respond_to?(:activate_all_subscribers) Spree::Event.activate_all_subscribers else Spree::Event.subscribers.each(&:subscribe!) end end end
Private Instance Methods
enable_solidus_engine_support(engine)
click to toggle source
Enables support for a Solidus engine.
This will tell Rails to:
* add +lib/controllers/[engine]+ to the controller paths; * add +lib/views/[engine]+ to the view paths; * load the decorators in +lib/decorators/[engine]+.
@see load_solidus_decorators_from
# File lib/solidus_support/engine_extensions.rb, line 84 def enable_solidus_engine_support(engine) paths['app/controllers'] << "lib/controllers/#{engine}" paths['app/views'] << "lib/views/#{engine}" path = root.join("lib/decorators/#{engine}") config.autoload_paths += path.glob('*') engine_context = self config.to_prepare do engine_context.instance_eval do load_solidus_decorators_from(path) end end end
solidus_decorators_root()
click to toggle source
Returns the root for this engine's decorators.
@return [Path]
# File lib/solidus_support/engine_extensions.rb, line 64 def solidus_decorators_root root.join('app/decorators') end
solidus_subscribers_root()
click to toggle source
Returns the root for this engine's Solidus event subscribers.
@return [Path]
# File lib/solidus_support/engine_extensions.rb, line 71 def solidus_subscribers_root root.join("app/subscribers") end