skypager 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94c154a8bda0bf80d4c7646f32c6cdec217ebb7a
4
- data.tar.gz: d1f3ba950aa3d496d91abd7ca8ea764b9215b88e
3
+ metadata.gz: c43ca74ddfecb4de61127287f5f14c6e2ca18145
4
+ data.tar.gz: 29eb227714e18fd39294ae82940a8e927cee8496
5
5
  SHA512:
6
- metadata.gz: d4018f3661eae1cf6579eff94394f6056323465955fec50b6a395b230eb6c3052915d42a7cc2625845f2d9eb5f846716d96be635a85d9f7ee89c02823806397a
7
- data.tar.gz: cfc34a307af6449d5b7be691d25e850ec9b7d3d27475fc19bb0a0e8c6000d960099f6d0cc75dd0e507940e85cb3be49358f349177b9c95c29a2fea3df81f0c29
6
+ metadata.gz: 96058ca42cfef710a4a0d7939319465f60a138fe328becdbae11b93741c54190c479c642597a0de5f668a800c6cb23a7fe0b822feddeeafd79916ec35e2d81ac
7
+ data.tar.gz: 7a973e4722f40ea57cd93634720e6d8a78838c2576f962004f7ddd9570d9e23589534d24493c12dbeae91fd3abca22824bf01bf59de1633e16bce538fa45f827
@@ -17,6 +17,8 @@ module Skypager
17
17
  end
18
18
 
19
19
  def self.protector(options={})
20
+ require 'skypager/protector'
21
+ require 'pry'
20
22
  Skypager::Protector.new(options)
21
23
  end
22
24
 
@@ -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
- serve_not_found_path
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.size.to_s
43
+ content_length = Rack::Utils.bytesize(content).to_s
43
44
 
44
- [200, {"Content-Type" => mime_type,"Content-Length" => content_length}, [content]]
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
- [404, {"Content-Type" => "text/html"}, [not_found_path.read]]
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 !path.to_s.match(/\.\w+/)
64
- path = path.gsub(/\/$/,'') + path_extension
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(/^\//,'')
@@ -1,3 +1,3 @@
1
1
  module Skypager
2
- VERSION = "2.1.3"
2
+ VERSION = "2.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skypager
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Soeder