innate 2012.03 → 2012.12
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/AUTHORS +2 -2
- data/CHANGELOG +996 -887
- data/MANIFEST +2 -2
- data/example/custom_middleware.rb +12 -8
- data/innate.gemspec +7 -7
- data/lib/innate.rb +90 -88
- data/lib/innate/action.rb +4 -5
- data/lib/innate/default_middleware.rb +22 -0
- data/lib/innate/helper/aspect.rb +185 -22
- data/lib/innate/lru_hash.rb +113 -0
- data/lib/innate/node.rb +13 -8
- data/lib/innate/options.rb +2 -5
- data/lib/innate/spec/bacon.rb +6 -8
- data/lib/innate/version.rb +1 -1
- data/lib/innate/view/erb.rb +1 -2
- data/lib/innate/view/etanni.rb +1 -2
- data/spec/innate/helper/flash.rb +1 -1
- metadata +56 -76
- data/lib/innate/middleware_compiler.rb +0 -66
- data/lib/innate/rack_file_wrapper.rb +0 -24
@@ -1,66 +0,0 @@
|
|
1
|
-
module Innate
|
2
|
-
class MiddlewareCompiler
|
3
|
-
COMPILED = {}
|
4
|
-
|
5
|
-
def self.build(name, &block)
|
6
|
-
COMPILED[name] ||= new(name, &block)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.build!(name, &block)
|
10
|
-
COMPILED[name] = new(name, &block)
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :middlewares, :name
|
14
|
-
|
15
|
-
def initialize(name)
|
16
|
-
@name = name.to_sym
|
17
|
-
@middlewares = []
|
18
|
-
@compiled = nil
|
19
|
-
yield(self) if block_given?
|
20
|
-
end
|
21
|
-
|
22
|
-
def use(middleware, *args, &block)
|
23
|
-
@middlewares << [middleware, args, block]
|
24
|
-
end
|
25
|
-
|
26
|
-
def apps(*middlewares)
|
27
|
-
@middlewares.concat(middlewares.map{|mw| [mw, [], nil]})
|
28
|
-
end
|
29
|
-
|
30
|
-
def run(app)
|
31
|
-
@app = app
|
32
|
-
end
|
33
|
-
|
34
|
-
def cascade(*apps)
|
35
|
-
@app = Rack::Cascade.new(apps, [404, 405])
|
36
|
-
end
|
37
|
-
|
38
|
-
# Default application for Innate
|
39
|
-
def innate(app = Innate::DynaMap, options = Innate.options)
|
40
|
-
roots, publics = options[:roots], options[:publics]
|
41
|
-
|
42
|
-
joined = roots.map{|root| publics.map{|public| ::File.join(root, public)}}
|
43
|
-
|
44
|
-
apps = joined.flatten.map{|public_root| RackFileWrapper.new(public_root) }
|
45
|
-
apps << Current.new(Route.new(app), Rewrite.new(app))
|
46
|
-
|
47
|
-
cascade(*apps)
|
48
|
-
end
|
49
|
-
|
50
|
-
def call(env)
|
51
|
-
compile
|
52
|
-
@compiled.call(env)
|
53
|
-
end
|
54
|
-
|
55
|
-
def compile
|
56
|
-
@compiled ? self : compile!
|
57
|
-
end
|
58
|
-
|
59
|
-
def compile!
|
60
|
-
@compiled = @middlewares.reverse.
|
61
|
-
inject(@app){|app, (middleware, args, block)|
|
62
|
-
middleware.new(app, *args, &block) }
|
63
|
-
self
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Innate
|
2
|
-
class RackFileWrapper
|
3
|
-
def initialize(root, cache_control = nil)
|
4
|
-
@file = Rack::File.new(root, cache_control)
|
5
|
-
end
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
status, header, body = @file.call(env)
|
9
|
-
|
10
|
-
if status == 403
|
11
|
-
unless Rack::File::ALLOWED_VERBS.include?(env['REQUEST_METHOD'])
|
12
|
-
body = "File not Found: #{Rack::Utils.unescape(env['PATH_INFO'])}\n"
|
13
|
-
return 404, {
|
14
|
-
'Content-Type' => 'text/plain',
|
15
|
-
'Content-Length' => body.size,
|
16
|
-
'X-Cascade' => 'pass',
|
17
|
-
}, [body]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
return status, header, body
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|