Skip to content

Commit

Permalink
Merge pull request #78 from jeremyf/refactor-method-abstraction
Browse files Browse the repository at this point in the history
Extracting method #load_configuration_load_paths!
  • Loading branch information
jodosha committed Nov 4, 2014
2 parents 134cc1e + 3874235 commit 2f28a6f
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/lotus/loader.rb
Expand Up @@ -22,7 +22,8 @@ def load!
@mutex.synchronize do
load_configuration!
load_frameworks!
load_application!
load_configuration_load_paths!
load_rack!
finalize!
end
end
Expand All @@ -35,8 +36,12 @@ def load_configuration!
end

def load_frameworks!
config = configuration
_load_controller_framework!
_load_view_framework!
end

def _load_controller_framework!
config = configuration
unless application_module.const_defined?('Controller')
controller = Lotus::Controller.duplicate(application_module) do
handle_exceptions config.handle_exceptions
Expand All @@ -47,7 +52,10 @@ def load_frameworks!

application_module.const_set('Controller', controller)
end
end

def _load_view_framework!
config = configuration
unless application_module.const_defined?('View')
view = Lotus::View.duplicate(application_module) do
root config.templates
Expand All @@ -58,22 +66,25 @@ def load_frameworks!
end
end

def load_application!
configuration.load_paths.load!(configuration.root)
load_rack!
end

def finalize!
application_module.module_eval %{
#{ application_module }::View.load!
}
end

def load_configuration_load_paths!
configuration.load_paths.load!(configuration.root)
end

def load_rack!
return if application.is_a?(Class)
_assign_rack_routes!
_load_rack_middleware!
_assign_routes_to_application_module!
end

def _assign_rack_routes!
namespace = configuration.namespace || application_module

resolver = Lotus::Routing::EndpointResolver.new(pattern: configuration.controller_pattern, namespace: namespace)
default_app = Lotus::Routing::Default.new
application.routes = Lotus::Router.new(
Expand All @@ -84,9 +95,14 @@ def load_rack!
port: configuration.port,
&configuration.routes
)
end

def _load_rack_middleware!
namespace = configuration.namespace || application_module
configuration.middleware.load!(application, namespace)
end

def _assign_routes_to_application_module!
unless application_module.const_defined?('Routes')
routes = Lotus::Routes.new(application.routes)
application_module.const_set('Routes', routes)
Expand Down

0 comments on commit 2f28a6f

Please sign in to comment.