Class: Deas::Server::Configuration

Inherits:
Object
  • Object
show all
Includes:
NsOptions::Proxy
Defined in:
lib/deas/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = nil) ⇒ Configuration

Returns a new instance of Configuration.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/deas/server.rb', line 46

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_folder => proc{ self.root.join('public') },
    :views_folder  => proc{ self.root.join('views') }
  }))
  @template_helpers = []
  @valid = nil
end

Instance Attribute Details

#template_helpersObject (readonly)

Returns the value of attribute template_helpers.



44
45
46
# File 'lib/deas/server.rb', line 44

def template_helpers
  @template_helpers
end

Instance Method Details

#template_scopeObject



93
94
95
96
97
# File 'lib/deas/server.rb', line 93

def template_scope
  Class.new(Deas::Template::Scope).tap do |klass|
    klass.send(:include, *self.template_helpers)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/deas/server.rb', line 59

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.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/deas/server.rb', line 66

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?

  # constantize the routes to ensure they are available
  self.routes.each(&:constantize!)

  # 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