Class: Deas::Server::Configuration
- Inherits:
-
Object
- Object
- Deas::Server::Configuration
- Includes:
- NsOptions::Proxy
- Defined in:
- lib/deas/server.rb
Instance Attribute Summary collapse
-
#error_procs ⇒ Object
Returns the value of attribute error_procs.
-
#init_procs ⇒ Object
Returns the value of attribute init_procs.
-
#middlewares ⇒ Object
Returns the value of attribute middlewares.
-
#router ⇒ Object
Returns the value of attribute router.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#template_helpers ⇒ Object
Returns the value of attribute template_helpers.
Instance Method Summary collapse
-
#initialize(values = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #routes ⇒ Object
- #template_scope ⇒ Object
- #urls ⇒ Object
- #valid? ⇒ Boolean
-
#validate! ⇒ Object
for the config to be considered “valid”, a few things need to happen.
Constructor Details
#initialize(values = nil) ⇒ Configuration
Returns a new instance of Configuration.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/deas/server.rb', line 41 def initialize(values=nil) # these are defaulted here because we want to use the Configuration # instance `root`. If we define a proc above, we will be using the # Configuration class `root`, which will not update these options as # expected. super((values || {}).merge({ :public_root => proc{ self.root.join('public') }, :views_root => proc{ self.root.join('views') } })) @settings = {} @error_procs, @init_procs, @template_helpers, @middlewares = [], [], [], [] @router = Deas::Router.new @valid = nil end |
Instance Attribute Details
#error_procs ⇒ Object
Returns the value of attribute error_procs.
38 39 40 |
# File 'lib/deas/server.rb', line 38 def error_procs @error_procs end |
#init_procs ⇒ Object
Returns the value of attribute init_procs.
38 39 40 |
# File 'lib/deas/server.rb', line 38 def init_procs @init_procs end |
#middlewares ⇒ Object
Returns the value of attribute middlewares.
39 40 41 |
# File 'lib/deas/server.rb', line 39 def middlewares @middlewares end |
#router ⇒ Object
Returns the value of attribute router.
39 40 41 |
# File 'lib/deas/server.rb', line 39 def router @router end |
#settings ⇒ Object
Returns the value of attribute settings.
38 39 40 |
# File 'lib/deas/server.rb', line 38 def settings @settings end |
#template_helpers ⇒ Object
Returns the value of attribute template_helpers.
38 39 40 |
# File 'lib/deas/server.rb', line 38 def template_helpers @template_helpers end |
Instance Method Details
#routes ⇒ Object
94 95 96 |
# File 'lib/deas/server.rb', line 94 def routes self.router.routes end |
#template_scope ⇒ Object
98 99 100 101 102 |
# File 'lib/deas/server.rb', line 98 def template_scope Class.new(Deas::Template::Scope).tap do |klass| klass.send(:include, *self.template_helpers) end end |
#urls ⇒ Object
90 91 92 |
# File 'lib/deas/server.rb', line 90 def urls self.router.urls end |
#valid? ⇒ Boolean
56 57 58 |
# File 'lib/deas/server.rb', line 56 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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/deas/server.rb', line 63 def validate! return @valid if !@valid.nil? # only need to run this once per config # ensure all user and plugin configs/settings are applied self.init_procs.each{ |p| p.call } raise Deas::ServerRootError if self.root.nil? # validate the routes self.routes.each(&:validate!) # set the :erb :outvar setting if it hasn't been set. this is used # by template helpers and plugins and needs to be queryable. the actual # value doesn't matter - it just needs to be set self.settings[:erb] ||= {} self.settings[:erb][:outvar] ||= '@_out_buf' # append the show exceptions and loggine 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 [*Deas::Logging.middleware(self.verbose_logging)].tap do |mw_args| self.middlewares << mw_args end @valid = true # if it made it this far, its valid! end |