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
-
#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.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/deas/server.rb', line 126 def initialize @env = DEFAULT_ENV @root = ENV['PWD'] @method_override = true @show_exceptions = false @verbose_logging = true @middlewares = [] @init_procs = [] @error_procs = [] @template_source = nil @logger = Deas::NullLogger.new @router = Deas::Router.new @valid = nil end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
121 122 123 |
# File 'lib/deas/server.rb', line 121 def env @env end |
#error_procs ⇒ Object
Returns the value of attribute error_procs.
123 124 125 |
# File 'lib/deas/server.rb', line 123 def error_procs @error_procs end |
#init_procs ⇒ Object
Returns the value of attribute init_procs.
123 124 125 |
# File 'lib/deas/server.rb', line 123 def init_procs @init_procs end |
#logger ⇒ Object
Returns the value of attribute logger.
124 125 126 |
# File 'lib/deas/server.rb', line 124 def logger @logger end |
#method_override ⇒ Object
Returns the value of attribute method_override.
122 123 124 |
# File 'lib/deas/server.rb', line 122 def method_override @method_override end |
#middlewares ⇒ Object
Returns the value of attribute middlewares.
123 124 125 |
# File 'lib/deas/server.rb', line 123 def middlewares @middlewares end |
#root ⇒ Object
Returns the value of attribute root.
121 122 123 |
# File 'lib/deas/server.rb', line 121 def root @root end |
#router ⇒ Object
Returns the value of attribute router.
124 125 126 |
# File 'lib/deas/server.rb', line 124 def router @router end |
#show_exceptions ⇒ Object
Returns the value of attribute show_exceptions.
122 123 124 |
# File 'lib/deas/server.rb', line 122 def show_exceptions @show_exceptions end |
#template_source ⇒ Object
Returns the value of attribute template_source.
124 125 126 |
# File 'lib/deas/server.rb', line 124 def template_source @template_source end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
122 123 124 |
# File 'lib/deas/server.rb', line 122 def verbose_logging @verbose_logging end |
Instance Method Details
#routes ⇒ Object
150 151 152 |
# File 'lib/deas/server.rb', line 150 def routes self.router.routes end |
#urls ⇒ Object
146 147 148 |
# File 'lib/deas/server.rb', line 146 def urls self.router.urls end |
#valid? ⇒ Boolean
154 155 156 |
# File 'lib/deas/server.rb', line 154 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.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/deas/server.rb', line 161 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 |