Class: Deas::Server::Config
- Inherits:
-
Object
- Object
- Deas::Server::Config
- Defined in:
- lib/deas/server.rb
Constant Summary collapse
- DEFAULT_ENV =
'development'.freeze
Instance Attribute Summary collapse
-
#after_route_run_procs ⇒ Object
Returns the value of attribute after_route_run_procs.
-
#before_route_run_procs ⇒ Object
Returns the value of attribute before_route_run_procs.
-
#env ⇒ Object
Returns the value of attribute env.
-
#error_procs ⇒ Object
Returns the value of attribute error_procs.
-
#init_procs ⇒ Object
Returns the value of attribute init_procs.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#method_override ⇒ Object
Returns the value of attribute method_override.
-
#middlewares ⇒ Object
Returns the value of attribute middlewares.
-
#root ⇒ Object
Returns the value of attribute root.
-
#router ⇒ Object
Returns the value of attribute router.
-
#show_exceptions ⇒ Object
Returns the value of attribute show_exceptions.
-
#template_source ⇒ Object
Returns the value of attribute template_source.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #routes ⇒ Object
- #urls ⇒ Object
- #valid? ⇒ Boolean
-
#validate! ⇒ Object
for the config to be considered “valid”, a few things need to happen.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/deas/server.rb', line 143 def initialize @env = DEFAULT_ENV @root = ENV['PWD'] @method_override = true @show_exceptions = false @verbose_logging = true @middlewares = [] @init_procs = [] @error_procs = [] @before_route_run_procs = [] @after_route_run_procs = [] @template_source = nil @logger = Deas::NullLogger.new @router = Deas::Router.new @valid = nil end |
Instance Attribute Details
#after_route_run_procs ⇒ Object
Returns the value of attribute after_route_run_procs.
140 141 142 |
# File 'lib/deas/server.rb', line 140 def after_route_run_procs @after_route_run_procs end |
#before_route_run_procs ⇒ Object
Returns the value of attribute before_route_run_procs.
140 141 142 |
# File 'lib/deas/server.rb', line 140 def before_route_run_procs @before_route_run_procs end |
#env ⇒ Object
Returns the value of attribute env.
137 138 139 |
# File 'lib/deas/server.rb', line 137 def env @env end |
#error_procs ⇒ Object
Returns the value of attribute error_procs.
139 140 141 |
# File 'lib/deas/server.rb', line 139 def error_procs @error_procs end |
#init_procs ⇒ Object
Returns the value of attribute init_procs.
139 140 141 |
# File 'lib/deas/server.rb', line 139 def init_procs @init_procs end |
#logger ⇒ Object
Returns the value of attribute logger.
141 142 143 |
# File 'lib/deas/server.rb', line 141 def logger @logger end |
#method_override ⇒ Object
Returns the value of attribute method_override.
138 139 140 |
# File 'lib/deas/server.rb', line 138 def method_override @method_override end |
#middlewares ⇒ Object
Returns the value of attribute middlewares.
139 140 141 |
# File 'lib/deas/server.rb', line 139 def middlewares @middlewares end |
#root ⇒ Object
Returns the value of attribute root.
137 138 139 |
# File 'lib/deas/server.rb', line 137 def root @root end |
#router ⇒ Object
Returns the value of attribute router.
141 142 143 |
# File 'lib/deas/server.rb', line 141 def router @router end |
#show_exceptions ⇒ Object
Returns the value of attribute show_exceptions.
138 139 140 |
# File 'lib/deas/server.rb', line 138 def show_exceptions @show_exceptions end |
#template_source ⇒ Object
Returns the value of attribute template_source.
141 142 143 |
# File 'lib/deas/server.rb', line 141 def template_source @template_source end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
138 139 140 |
# File 'lib/deas/server.rb', line 138 def verbose_logging @verbose_logging end |
Instance Method Details
#routes ⇒ Object
169 170 171 |
# File 'lib/deas/server.rb', line 169 def routes self.router.routes end |
#urls ⇒ Object
165 166 167 |
# File 'lib/deas/server.rb', line 165 def urls self.router.urls end |
#valid? ⇒ Boolean
173 174 175 |
# File 'lib/deas/server.rb', line 173 def valid? !!@valid end |
#validate! ⇒ Object
for the config to be considered “valid”, a few things need to happen. The key here is that this only needs to be done once for each config.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/deas/server.rb', line 180 def validate! return @valid if !@valid.nil? # only need to run this once per config # ensure all user and plugin configs are applied self.init_procs.each(&:call) raise Deas::ServerRootError if self.root.nil? # validate the router self.router.validate! # TODO: build final middleware stack when building the rack app, not here # (once Sinatra is removed) # prepend the method override middleware first. This ensures that the # it is run before any other middleware self.middlewares.unshift([Rack::MethodOverride]) if self.method_override # append the show exceptions and logging middlewares last. This ensures # that the logging and exception showing happens just before the app gets # the request and just after the app sends a response. self.middlewares << [Deas::ShowExceptions] if self.show_exceptions self.middlewares << Deas::Logging.middleware_args(self.verbose_logging) self.middlewares.freeze @valid = true # if it made it this far, its valid! end |