low 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/lib/low/mongo/heroku.rb +3 -0
- data/lib/low/mongo/util.rb +1 -0
- data/lib/low/mongo.rb +0 -3
- data/lib/low/{middleware → rack}/log_level.rb +1 -1
- data/lib/low/{middleware → rack}/rack_errors.rb +1 -1
- data/lib/low/{middleware → rack}/request_id.rb +4 -2
- data/lib/low/{middleware → rack}/request_logger.rb +2 -1
- data/lib/low/{middleware → rack}/subdomain_map.rb +1 -1
- data/lib/low/version.rb +1 -1
- data/lib/low.rb +2 -10
- data/spec/low/mongo/util_spec.rb +2 -0
- data/spec/low/mongo_spec.rb +1 -0
- data/spec/low/{middleware → rack}/log_level_spec.rb +9 -8
- data/spec/low/{middleware → rack}/rack_errors_spec.rb +6 -5
- data/spec/low/{middleware → rack}/request_id_spec.rb +3 -2
- data/spec/low/{middleware → rack}/request_logger_spec.rb +4 -2
- data/spec/low/{middleware → rack}/subdomain_map_spec.rb +3 -2
- data/spec/low/scoped_logger_spec.rb +1 -0
- metadata +18 -17
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/lib/low/mongo/heroku.rb
CHANGED
data/lib/low/mongo/util.rb
CHANGED
data/lib/low/mongo.rb
CHANGED
@@ -4,9 +4,6 @@ module Low
|
|
4
4
|
# The `Mongo` module defines an interface for a Mongo helper
|
5
5
|
# class. It also includes two basic classes, `Local` and `Remote`.
|
6
6
|
module Mongo
|
7
|
-
autoload :Heroku, 'low/mongo/heroku'
|
8
|
-
autoload :Util, 'low/mongo/util'
|
9
|
-
|
10
7
|
# Simple access to a Mongo::Collection instance.
|
11
8
|
def [](collection)
|
12
9
|
db[collection]
|
@@ -1,5 +1,7 @@
|
|
1
|
+
require 'rack/request'
|
2
|
+
|
1
3
|
module Low
|
2
|
-
module
|
4
|
+
module Rack
|
3
5
|
# `RequestId` adds a value for env["request_id"]. `RequestLogger`, for one,
|
4
6
|
# uses this value to scope the logger it instantiates.
|
5
7
|
class RequestId
|
@@ -20,7 +22,7 @@ module Low
|
|
20
22
|
|
21
23
|
def call(env)
|
22
24
|
# If there is a request_id parameter,
|
23
|
-
req = Rack::Request.new(env)
|
25
|
+
req = ::Rack::Request.new(env)
|
24
26
|
|
25
27
|
# and it's valid, use it;
|
26
28
|
if req['request_id'] and RequestId.is_valid?(req['request_id'])
|
data/lib/low/version.rb
CHANGED
data/lib/low.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
|
+
$:.push File.dirname(__FILE__)
|
2
|
+
|
1
3
|
require 'low/version'
|
2
4
|
|
3
5
|
module Low
|
4
|
-
autoload :ScopedLogger, 'low/scoped_logger'
|
5
|
-
autoload :Mongo, 'low/mongo'
|
6
|
-
|
7
|
-
module Middleware
|
8
|
-
autoload :LogLevel, 'low/middleware/log_level'
|
9
|
-
autoload :RackErrors, 'low/middleware/rack_errors'
|
10
|
-
autoload :RequestId, 'low/middleware/request_id'
|
11
|
-
autoload :RequestLogger, 'low/middleware/request_logger'
|
12
|
-
autoload :SubdomainMap, 'low/middleware/subdomain_map'
|
13
|
-
end
|
14
6
|
end
|
data/spec/low/mongo/util_spec.rb
CHANGED
data/spec/low/mongo_spec.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'logger'
|
3
|
+
require 'low/rack/log_level'
|
3
4
|
|
4
|
-
describe Low::
|
5
|
+
describe Low::Rack::LogLevel do
|
5
6
|
def test_app
|
6
7
|
lambda do |env|
|
7
8
|
[200, {'Content-Type' => 'text/plain'}, env['low.log_level']]
|
@@ -13,49 +14,49 @@ describe Low::Middleware::LogLevel do
|
|
13
14
|
|
14
15
|
it 'should set low.log_level to `Logger::FATAL` if LOG_LEVEL is \'FATAL\'' do
|
15
16
|
ENV['LOG_LEVEL'] = 'FATAL'
|
16
|
-
rack = Low::
|
17
|
+
rack = Low::Rack::LogLevel.new test_app
|
17
18
|
response = rack.call({})
|
18
19
|
response[2].should == Logger::FATAL
|
19
20
|
end
|
20
21
|
|
21
22
|
it 'should set low.log_level to `Logger::ERROR` if LOG_LEVEL is \'ERROR\'' do
|
22
23
|
ENV['LOG_LEVEL'] = 'ERROR'
|
23
|
-
rack = Low::
|
24
|
+
rack = Low::Rack::LogLevel.new test_app
|
24
25
|
response = rack.call({})
|
25
26
|
response[2].should == Logger::ERROR
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'should set low.log_level to `Logger::WARN` if LOG_LEVEL is \'WARN\'' do
|
29
30
|
ENV['LOG_LEVEL'] = 'WARN'
|
30
|
-
rack = Low::
|
31
|
+
rack = Low::Rack::LogLevel.new test_app
|
31
32
|
response = rack.call({})
|
32
33
|
response[2].should == Logger::WARN
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'should set low.log_level to `Logger::INFO` if LOG_LEVEL is \'INFO\'' do
|
36
37
|
ENV['LOG_LEVEL'] = 'INFO'
|
37
|
-
rack = Low::
|
38
|
+
rack = Low::Rack::LogLevel.new test_app
|
38
39
|
response = rack.call({})
|
39
40
|
response[2].should == Logger::INFO
|
40
41
|
end
|
41
42
|
|
42
43
|
it 'should set low.log_level to `Logger::DEBUG` if LOG_LEVEL is \'DEBUG\'' do
|
43
44
|
ENV['LOG_LEVEL'] = 'DEBUG'
|
44
|
-
rack = Low::
|
45
|
+
rack = Low::Rack::LogLevel.new test_app
|
45
46
|
response = rack.call({})
|
46
47
|
response[2].should == Logger::DEBUG
|
47
48
|
end
|
48
49
|
|
49
50
|
it 'should set low.log_level to `Logger::INFO` if neither LOG_LEVEL nor `:default_level` is set' do
|
50
51
|
ENV['LOG_LEVEL'] = nil
|
51
|
-
rack = Low::
|
52
|
+
rack = Low::Rack::LogLevel.new test_app
|
52
53
|
response = rack.call({})
|
53
54
|
response[2].should == Logger::INFO
|
54
55
|
end
|
55
56
|
|
56
57
|
it 'should set low.log_level to the specified `:default_level` if LOG_LEVEL is not set' do
|
57
58
|
ENV['LOG_LEVEL'] = nil
|
58
|
-
rack = Low::
|
59
|
+
rack = Low::Rack::LogLevel.new test_app, default_level: Logger::DEBUG
|
59
60
|
response = rack.call({})
|
60
61
|
response[2].should == Logger::DEBUG
|
61
62
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'low/rack/rack_errors'
|
3
4
|
|
4
|
-
describe Low::
|
5
|
+
describe Low::Rack::RackErrors do
|
5
6
|
def test_app
|
6
7
|
lambda do |env|
|
7
8
|
[200, {'Content-Type' => 'text/plain'}, env['rack.errors']]
|
@@ -14,28 +15,28 @@ describe Low::Middleware::RackErrors do
|
|
14
15
|
|
15
16
|
it 'should log to the FS in the development RACK_ENV by default' do
|
16
17
|
ENV['RACK_ENV'] = 'development'
|
17
|
-
rack = Low::
|
18
|
+
rack = Low::Rack::RackErrors.new test_app
|
18
19
|
response = rack.call({})
|
19
20
|
response[2].path.should == 'log/development.log'
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'should log to the FS in the test RACK_ENV by default' do
|
23
24
|
ENV['RACK_ENV'] = 'test'
|
24
|
-
rack = Low::
|
25
|
+
rack = Low::Rack::RackErrors.new test_app
|
25
26
|
response = rack.call({})
|
26
27
|
response[2].path.should == 'log/test.log'
|
27
28
|
end
|
28
29
|
|
29
30
|
it 'should log to the FS in the specified RACK_ENV' do
|
30
31
|
ENV['RACK_ENV'] = 'production'
|
31
|
-
rack = Low::
|
32
|
+
rack = Low::Rack::RackErrors.new test_app, fs_envs: ['production']
|
32
33
|
response = rack.call({})
|
33
34
|
response[2].path.should == 'log/production.log'
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'should log to STDOUT if not in a specified RACK_ENV' do
|
37
38
|
ENV['RACK_ENV'] = 'production'
|
38
|
-
rack = Low::
|
39
|
+
rack = Low::Rack::RackErrors.new test_app
|
39
40
|
response = rack.call({})
|
40
41
|
response[2].should == STDOUT
|
41
42
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'low/rack/request_id'
|
2
3
|
|
3
|
-
describe Low::
|
4
|
+
describe Low::Rack::RequestId do
|
4
5
|
def app
|
5
6
|
app = lambda do |env|
|
6
7
|
[200, {'Content-Type' => 'text/plain'}, ['Request Id: ' + env['useless.request_id']]]
|
7
8
|
end
|
8
9
|
|
9
|
-
Low::
|
10
|
+
Low::Rack::RequestId.new(app)
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'should add a request ID to the env while proxying transparently' do
|
@@ -1,7 +1,9 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
require 'logger'
|
3
|
+
require 'low/scoped_logger'
|
4
|
+
require 'low/rack/request_logger'
|
3
5
|
|
4
|
-
describe Low::
|
6
|
+
describe Low::Rack::RequestLogger do
|
5
7
|
def test_app
|
6
8
|
lambda do |env|
|
7
9
|
[200, {'Content-Type' => 'text/plain'}, env['rack.logger']]
|
@@ -10,7 +12,7 @@ describe Low::Middleware::RequestLogger do
|
|
10
12
|
|
11
13
|
it 'should set rack.logger to an instance of `Low::ScopedLogger` with scope set to \'request_id\'
|
12
14
|
and level set to \'low.log_level\'' do
|
13
|
-
rack = Low::
|
15
|
+
rack = Low::Rack::RequestLogger.new test_app
|
14
16
|
response = rack.call({'request_id' => 'abc123', 'low.log_level' => Logger::FATAL})
|
15
17
|
logger = response[2]
|
16
18
|
logger.should be_a(Low::ScopedLogger)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require 'low/rack/subdomain_map'
|
2
3
|
|
3
|
-
describe Low::
|
4
|
+
describe Low::Rack::SubdomainMap do
|
4
5
|
def map
|
5
6
|
default_app = lambda do |env|
|
6
7
|
[200, {'Content-Type' => 'text/plain'}, ['Default App']]
|
@@ -10,7 +11,7 @@ describe Low::Middleware::SubdomainMap do
|
|
10
11
|
[200, {'Content-Type' => 'text/plain'}, ['API App']]
|
11
12
|
end
|
12
13
|
|
13
|
-
Low::
|
14
|
+
Low::Rack::SubdomainMap.new default_app, 'subdomain' => api_app
|
14
15
|
end
|
15
16
|
|
16
17
|
it 'should call the default app if no subdomain is specified' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: low
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -99,30 +99,31 @@ extensions: []
|
|
99
99
|
extra_rdoc_files: []
|
100
100
|
files:
|
101
101
|
- .gitignore
|
102
|
+
- .rspec
|
102
103
|
- Gemfile
|
103
104
|
- Gemfile.lock
|
104
105
|
- LICENSE
|
105
106
|
- README.md
|
106
107
|
- Rakefile
|
107
108
|
- lib/low.rb
|
108
|
-
- lib/low/middleware/log_level.rb
|
109
|
-
- lib/low/middleware/rack_errors.rb
|
110
|
-
- lib/low/middleware/request_id.rb
|
111
|
-
- lib/low/middleware/request_logger.rb
|
112
|
-
- lib/low/middleware/subdomain_map.rb
|
113
109
|
- lib/low/mongo.rb
|
114
110
|
- lib/low/mongo/heroku.rb
|
115
111
|
- lib/low/mongo/util.rb
|
112
|
+
- lib/low/rack/log_level.rb
|
113
|
+
- lib/low/rack/rack_errors.rb
|
114
|
+
- lib/low/rack/request_id.rb
|
115
|
+
- lib/low/rack/request_logger.rb
|
116
|
+
- lib/low/rack/subdomain_map.rb
|
116
117
|
- lib/low/scoped_logger.rb
|
117
118
|
- lib/low/version.rb
|
118
119
|
- low.gemspec
|
119
|
-
- spec/low/middleware/log_level_spec.rb
|
120
|
-
- spec/low/middleware/rack_errors_spec.rb
|
121
|
-
- spec/low/middleware/request_id_spec.rb
|
122
|
-
- spec/low/middleware/request_logger_spec.rb
|
123
|
-
- spec/low/middleware/subdomain_map_spec.rb
|
124
120
|
- spec/low/mongo/util_spec.rb
|
125
121
|
- spec/low/mongo_spec.rb
|
122
|
+
- spec/low/rack/log_level_spec.rb
|
123
|
+
- spec/low/rack/rack_errors_spec.rb
|
124
|
+
- spec/low/rack/request_id_spec.rb
|
125
|
+
- spec/low/rack/request_logger_spec.rb
|
126
|
+
- spec/low/rack/subdomain_map_spec.rb
|
126
127
|
- spec/low/scoped_logger_spec.rb
|
127
128
|
- spec/spec_helper.rb
|
128
129
|
homepage: ''
|
@@ -150,12 +151,12 @@ signing_key:
|
|
150
151
|
specification_version: 3
|
151
152
|
summary: A low-level utility library.
|
152
153
|
test_files:
|
153
|
-
- spec/low/middleware/log_level_spec.rb
|
154
|
-
- spec/low/middleware/rack_errors_spec.rb
|
155
|
-
- spec/low/middleware/request_id_spec.rb
|
156
|
-
- spec/low/middleware/request_logger_spec.rb
|
157
|
-
- spec/low/middleware/subdomain_map_spec.rb
|
158
154
|
- spec/low/mongo/util_spec.rb
|
159
155
|
- spec/low/mongo_spec.rb
|
156
|
+
- spec/low/rack/log_level_spec.rb
|
157
|
+
- spec/low/rack/rack_errors_spec.rb
|
158
|
+
- spec/low/rack/request_id_spec.rb
|
159
|
+
- spec/low/rack/request_logger_spec.rb
|
160
|
+
- spec/low/rack/subdomain_map_spec.rb
|
160
161
|
- spec/low/scoped_logger_spec.rb
|
161
162
|
- spec/spec_helper.rb
|