Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lotus Application Frameworks Isolation

It would be necessary something like:

MyApp::Application.configuration.frameworks << [:controller]
MyApp::Application.load!

This way, we would not load Lotus::View into memory, duplicate and configure it, since we wouldn't be using it.

diff --git a/lib/lotus/application.rb b/lib/lotus/application.rb
index e730b41..3b1d07c 100644
--- a/lib/lotus/application.rb
+++ b/lib/lotus/application.rb
@@ -1,5 +1,4 @@
require 'lotus/utils/class_attribute'
-require 'lotus/frameworks'
require 'lotus/configuration'
require 'lotus/loader'
require 'lotus/rendering_policy'
diff --git a/lib/lotus/frameworks.rb b/lib/lotus/frameworks.rb
index 1f12cc5..e69de29 100644
--- a/lib/lotus/frameworks.rb
+++ b/lib/lotus/frameworks.rb
@@ -1,26 +0,0 @@
-require 'lotus/router'
-require 'lotus/controller'
-require 'lotus/view'
-
-module Lotus
- module Frameworks
- module Action
- module Rack
- protected
- def response
- super << self
- end
- end
- end
- end
-end
-
-Lotus::Action::Rack.class_eval do
- prepend Lotus::Frameworks::Action::Rack
-end
-
-Lotus::Action.class_eval do
- def to_rendering
- exposures.merge(format: format)
- end
-end
diff --git a/lib/lotus/frameworks/controller.rb b/lib/lotus/frameworks/controller.rb
new file mode 100644
index 0000000..66ef21e
--- /dev/null
+++ b/lib/lotus/frameworks/controller.rb
@@ -0,0 +1,24 @@
+require 'lotus/controller'
+
+module Lotus
+ module Frameworks
+ module Action
+ module Rack
+ protected
+ def response
+ super << self
+ end
+ end
+ end
+ end
+end
+
+Lotus::Action::Rack.class_eval do
+ prepend Lotus::Frameworks::Action::Rack
+end
+
+Lotus::Action.class_eval do
+ def to_rendering
+ exposures.merge(format: format)
+ end
+end
diff --git a/lib/lotus/frameworks/router.rb b/lib/lotus/frameworks/router.rb
new file mode 100644
index 0000000..6037544
--- /dev/null
+++ b/lib/lotus/frameworks/router.rb
@@ -0,0 +1 @@
+require 'lotus/router'
diff --git a/lib/lotus/frameworks/view.rb b/lib/lotus/frameworks/view.rb
new file mode 100644
index 0000000..816bc3a
--- /dev/null
+++ b/lib/lotus/frameworks/view.rb
@@ -0,0 +1 @@
+require 'lotus/view'
diff --git a/lib/lotus/loader.rb b/lib/lotus/loader.rb
index e038d7f..6e1d04c 100644
--- a/lib/lotus/loader.rb
+++ b/lib/lotus/loader.rb
@@ -23,7 +23,6 @@ module Lotus
load_configuration!
load_frameworks!
load_application!
- finalize!
end
end
@@ -38,27 +37,39 @@ module Lotus
config = configuration
unless application_module.const_defined?('Controller')
- controller = Lotus::Controller.duplicate(application_module) do
- handle_exceptions config.handle_exceptions
- default_format config.default_format
+ if configuration.frameworks.include?(:controller)
+ require "lotus/frameworks/controller"
- modules { include Lotus::Action::Cookies } if config.cookies
- end
+ controller = Lotus::Controller.duplicate(application_module) do
+ handle_exceptions config.handle_exceptions
+ default_format config.default_format
+
+ modules { include Lotus::Action::Cookies } if config.cookies
+ end
- application_module.const_set('Controller', controller)
+ application_module.const_set('Controller', controller)
+ end
end
unless application_module.const_defined?('View')
- view = Lotus::View.duplicate(application_module) do
- root config.templates
- layout config.layout
- end
+ if configuration.frameworks.include?(:view)
+ require "lotus/frameworks/view"
+
+ view = Lotus::View.duplicate(application_module) do
+ root config.templates
+ layout config.layout
+ end
- application_module.const_set('View', view)
+ application_module.const_set('View', view)
+
+ finalize!
+ end
end
end
def load_application!
+ return if application.is_a?(Class)
+
configuration.load_paths.load!(configuration.root)
load_rack!
end
@@ -70,7 +81,7 @@ module Lotus
end
def load_rack!
- return if application.is_a?(Class)
+ require "lotus/frameworks/router"
namespace = configuration.namespace || application_module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.