Class: Fewer::App
- Inherits:
-
Object
- Object
- Fewer::App
- Defined in:
- lib/fewer/app.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#engine_klass ⇒ Object
readonly
Returns the value of attribute engine_klass.
-
#engine_options ⇒ Object
readonly
Returns the value of attribute engine_options.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #engine(names) ⇒ Object
-
#initialize(name, options = {}) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(name, options = {}) ⇒ App
Returns a new instance of App.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fewer/app.rb', line 15 def initialize(name, = {}) @engine_klass = [:engine] @engine_options = [:engine_options] || {} @mount = [:mount] @root = [:root] @cache = [:cache] || 3600 * 24 * 365 raise ArgumentError.new('You need to define an :engine class') unless @engine_klass raise ArgumentError.new('You need to define a :root path') unless @root self.class.apps[name] = self end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
13 14 15 |
# File 'lib/fewer/app.rb', line 13 def cache @cache end |
#engine_klass ⇒ Object (readonly)
Returns the value of attribute engine_klass.
13 14 15 |
# File 'lib/fewer/app.rb', line 13 def engine_klass @engine_klass end |
#engine_options ⇒ Object (readonly)
Returns the value of attribute engine_options.
13 14 15 |
# File 'lib/fewer/app.rb', line 13 def @engine_options end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/fewer/app.rb', line 13 def name @name end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
13 14 15 |
# File 'lib/fewer/app.rb', line 13 def root @root end |
Class Method Details
.[](name) ⇒ Object
4 5 6 |
# File 'lib/fewer/app.rb', line 4 def [](name) apps[name] end |
.apps ⇒ Object
8 9 10 |
# File 'lib/fewer/app.rb', line 8 def apps @apps ||= {} end |
Instance Method Details
#call(env) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fewer/app.rb', line 26 def call(env) eng = engine(sources_from_path(env['PATH_INFO'])) if env["HTTP_IF_NONE_MATCH"] && env["HTTP_IF_NONE_MATCH"] == eng.etag Fewer.logger.debug "Fewer: returning 304 not modified" [304, {}, []] else headers = { 'Content-Type' => engine_klass.content_type || 'text/plain', 'Cache-Control' => "public, max-age=#{cache}", 'Last-Modified' => eng.mtime.rfc2822, 'ETag' => eng.etag } [200, headers, [eng.read]] end rescue Fewer::MissingSourceFileError => e [404, { 'Content-Type' => 'text/plain' }, [e.]] rescue StandardError => e [500, { 'Content-Type' => 'text/plain' }, ["#{e.class}: #{e.}"]] end |
#engine(names) ⇒ Object
48 49 50 |
# File 'lib/fewer/app.rb', line 48 def engine(names) engine_klass.new(root, names, ) end |