rack-app 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9db5bf57a1cc7db597b8f23aee6228a8d82412ef
4
- data.tar.gz: d815b86a8348006082e616e1feccc6a2f4a90d2c
3
+ metadata.gz: 16ea665e2afdada4efa387171cadf926a87aa993
4
+ data.tar.gz: 5fcae940c35142946c418d11a4c8f929c1c120b6
5
5
  SHA512:
6
- metadata.gz: da155363a4645977acaa3c49a6d5f5689919618b5ba4a4b25307ff6a8fa1405f3b731605dbd6e152087fdc5ad0a187a7dab7a6bb83f3e7966deba18b360b504f
7
- data.tar.gz: 31e97114d7a842b112eb98e1f4e66e149a9b4b8484d118b6087e9ee3c26c916450473ab6bd6c47ad0bf2f212a24487b23a436f217cd7a3a1cdd6079d7aa7ddf4
6
+ metadata.gz: a2032686e3243cdd0927dc5846baccdcaaba46ad7d88b300068e60886776af4cbdee53b6bb3c07cbaeb7d68fcec2b2d3a4ca506b1e89038e58b934780ede386e
7
+ data.tar.gz: 6f06939247a4f3d1c53364703b8b07e77008822da3f6d05f78d965c97b88b15b01a1b50768401834e8fd2c08d5ae99cafcee875860af73f0337c2bc505bc8ac8
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [travis-link]: http://travis-ci.org/rack-app/rack-app
5
5
  [travis-home]: http://travis-ci.org/
6
6
 
7
- ![Rack::App](http://rack-app-website.herokuapp.com/image/msruby_new.png)
7
+ ![Rack::App](http://rack-app-website.herokuapp.com/image/msruby_old.png)
8
8
 
9
9
  Your next favourite rack based micro framework that is totally addition free!
10
10
  Have a cup of awesomeness with your performance designed framework!
@@ -40,6 +40,11 @@ Or install it yourself as:
40
40
 
41
41
  $ gem install rack-app
42
42
 
43
+
44
+ ## Is it Production ready?
45
+
46
+ Yes, in fact it's already powering heroku hosted micro-services.
47
+
43
48
  ## Usage
44
49
 
45
50
  config.ru
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.17.0
1
+ 0.18.0
@@ -24,7 +24,7 @@ class Rack::App
24
24
  endpoint = router.fetch_endpoint(
25
25
  request_env['REQUEST_METHOD'],
26
26
  request_env[Rack::App::Constants::NORMALIZED_REQUEST_PATH])
27
- endpoint.execute(request_env)
27
+ endpoint.call(request_env)
28
28
  end
29
29
 
30
30
  def description(*description_texts)
@@ -64,18 +64,18 @@ class Rack::App
64
64
  def root(endpoint_path)
65
65
  options '/' do
66
66
  endpoint = self.class.router.fetch_endpoint('OPTIONS', Rack::App::Utils.normalize_path(endpoint_path))
67
- endpoint.get_response_body(request,response)
67
+ endpoint.get_response_body(request, response)
68
68
  end
69
69
  get '/' do
70
70
  endpoint = self.class.router.fetch_endpoint('GET', Rack::App::Utils.normalize_path(endpoint_path))
71
- endpoint.get_response_body(request,response)
71
+ endpoint.get_response_body(request, response)
72
72
  end
73
73
  end
74
74
 
75
- def error(*exception_classes,&block)
75
+ def error(*exception_classes, &block)
76
76
  @error_handler ||= Rack::App::ErrorHandler.new
77
77
  unless block.nil?
78
- @error_handler.register_handler(exception_classes,block)
78
+ @error_handler.register_handler(exception_classes, block)
79
79
  end
80
80
 
81
81
  return @error_handler
@@ -87,18 +87,15 @@ class Rack::App
87
87
 
88
88
  def add_route(request_method, request_path, &block)
89
89
 
90
- endpoint_properties = {
91
- :user_defined_logic => block,
92
- :default_headers => headers,
93
- :request_method => request_method,
94
- :error_handler => error,
95
- :request_path => request_path,
96
- :description => @last_description,
97
- :serializer => serializer,
98
- :app_class => self
99
- }
90
+ properties = endpoint_properties.merge(
91
+ {
92
+ :user_defined_logic => block,
93
+ :request_method => request_method,
94
+ :request_path => request_path,
95
+ }
96
+ )
100
97
 
101
- endpoint = Rack::App::Endpoint.new(endpoint_properties)
98
+ endpoint = Rack::App::Endpoint.new(properties)
102
99
  router.add_endpoint(request_method, request_path, endpoint)
103
100
 
104
101
  @last_description = nil
@@ -106,6 +103,13 @@ class Rack::App
106
103
 
107
104
  end
108
105
 
106
+ def serve_files_from(relative_path, options={})
107
+ options.merge!(endpoint_properties)
108
+ file_server = Rack::App::File::Server.new(relative_path, options)
109
+ request_path = Rack::App::Utils.join(file_server.namespace, '**', '*')
110
+ router.add_endpoint('GET', request_path, file_server)
111
+ end
112
+
109
113
  def mount(api_class)
110
114
 
111
115
  unless api_class.is_a?(Class) and api_class <= Rack::App
@@ -133,6 +137,18 @@ class Rack::App
133
137
  @headers
134
138
  end
135
139
 
140
+ protected
141
+
142
+ def endpoint_properties
143
+ {
144
+ :default_headers => headers,
145
+ :error_handler => error,
146
+ :description => @last_description,
147
+ :serializer => serializer,
148
+ :app_class => self
149
+ }
150
+ end
151
+
136
152
  end
137
153
 
138
154
  def params
@@ -16,13 +16,12 @@ class Rack::App::Endpoint
16
16
  @endpoint_method_name = register_method_to_app_class(properties[:user_defined_logic])
17
17
  end
18
18
 
19
- def execute(request_env)
19
+ def call(request_env)
20
20
 
21
21
  request = Rack::Request.new(request_env)
22
22
  response = Rack::Response.new
23
23
 
24
24
  set_response_body(response, get_response_body(request, response))
25
-
26
25
  return response.finish
27
26
 
28
27
  end
@@ -1,12 +1,13 @@
1
1
  class Rack::App::File::Server
2
2
 
3
+ attr_reader :namespace, :properties
4
+
3
5
  def initialize(root_folder, options={})
4
6
  require 'rack/file'
5
7
 
6
- namespace = formatted_namespace(options)
7
- namespace.freeze
8
-
9
- @namespace_rgx = /#{Regexp.escape(namespace)}/.freeze
8
+ @properties = options
9
+ @namespace = formatted_namespace(options).freeze
10
+ @namespace_rgx = /#{Regexp.escape(@namespace)}/.freeze
10
11
  @rack_file_server = ::Rack::File.new(Rack::App::Utils.pwd(root_folder), {})
11
12
 
12
13
  end
@@ -16,6 +17,9 @@ class Rack::App::File::Server
16
17
  @rack_file_server.call(env)
17
18
  end
18
19
 
20
+ def register_path_params_matcher(*args)
21
+ end
22
+
19
23
  protected
20
24
 
21
25
  def raw_namespace(options)
@@ -66,6 +66,7 @@ module Rack::App::Test
66
66
  "REQUEST_METHOD" => request_method.to_s.upcase,
67
67
  "REQUEST_PATH" => url,
68
68
  "REQUEST_URI" => url,
69
+ "PATH_INFO" => url,
69
70
  "SERVER_PROTOCOL" => "HTTP/1.1",
70
71
  "CONTENT_LENGTH" => "0",
71
72
  "CONTENT_TYPE" => "application/x-www-form-urlencoded",
@@ -37,4 +37,8 @@ module Rack::App::Utils
37
37
  "%08x-%04x-%04x-%04x-%04x%08x" % ary
38
38
  end
39
39
 
40
+ def join(*url_path_parts)
41
+ File.join(*url_path_parts).gsub(File::Separator,'/').sub(/^\/?(.*)$/,'/\1')
42
+ end
43
+
40
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-09 00:00:00.000000000 Z
12
+ date: 2016-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler