skypager 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/skypager.rb +2 -0
- data/lib/skypager/protector.rb +13 -9
- data/lib/skypager/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c43ca74ddfecb4de61127287f5f14c6e2ca18145
|
4
|
+
data.tar.gz: 29eb227714e18fd39294ae82940a8e927cee8496
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96058ca42cfef710a4a0d7939319465f60a138fe328becdbae11b93741c54190c479c642597a0de5f668a800c6cb23a7fe0b822feddeeafd79916ec35e2d81ac
|
7
|
+
data.tar.gz: 7a973e4722f40ea57cd93634720e6d8a78838c2576f962004f7ddd9570d9e23589534d24493c12dbeae91fd3abca22824bf01bf59de1633e16bce538fa45f827
|
data/lib/skypager.rb
CHANGED
data/lib/skypager/protector.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# It should either show a login page, or the requested path
|
5
5
|
module Skypager
|
6
6
|
class Protector
|
7
|
-
attr_accessor :validator, :options
|
7
|
+
attr_accessor :validator, :options, :app
|
8
8
|
|
9
9
|
# Skypager::Protector.new(options) do |request|
|
10
10
|
# # validate request here
|
@@ -14,7 +14,8 @@ module Skypager
|
|
14
14
|
# - build_dir: defaults to ./build
|
15
15
|
# - login_path: defaults to /login/index.html
|
16
16
|
# - not_found_path: defaults to /not-found.html
|
17
|
-
def initialize(options={}, &validator)
|
17
|
+
def initialize(app, options={}, &validator)
|
18
|
+
@app = app
|
18
19
|
@options = options
|
19
20
|
@validator = validator
|
20
21
|
end
|
@@ -32,16 +33,16 @@ module Skypager
|
|
32
33
|
if file.exist?
|
33
34
|
serve_file(file)
|
34
35
|
else
|
35
|
-
|
36
|
+
@app.call(env)
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
39
|
-
def serve_file(file)
|
40
|
+
def serve_file(file, status=200)
|
40
41
|
mime_type = Rack::Mime.mime_type(Pathname(file).extname).to_s
|
41
42
|
content = Pathname(file).read.to_s
|
42
|
-
content_length = content.
|
43
|
+
content_length = Rack::Utils.bytesize(content).to_s
|
43
44
|
|
44
|
-
[
|
45
|
+
[status, {"Content-Type" => mime_type,"Content-Length" => content_length}, [content]]
|
45
46
|
end
|
46
47
|
|
47
48
|
def build_path
|
@@ -51,7 +52,7 @@ module Skypager
|
|
51
52
|
|
52
53
|
def serve_not_found_path
|
53
54
|
not_found_path = options.fetch(:not_found_path, "/not-found.html")
|
54
|
-
|
55
|
+
serve_file(not_found_path, 404)
|
55
56
|
end
|
56
57
|
|
57
58
|
def serve_login_path
|
@@ -60,8 +61,11 @@ module Skypager
|
|
60
61
|
end
|
61
62
|
|
62
63
|
def normalize_path(path)
|
63
|
-
if
|
64
|
-
path =
|
64
|
+
if path == "/"
|
65
|
+
path = "/index.html"
|
66
|
+
elsif !path.to_s.match(/\.\w+/)
|
67
|
+
path.gsub!(/\/$/,'')
|
68
|
+
path + path_extension
|
65
69
|
end
|
66
70
|
|
67
71
|
path.to_s.gsub(/^\//,'')
|
data/lib/skypager/version.rb
CHANGED