x_runtime 0.4.0 → 0.4.1

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.
data/README.markdown CHANGED
@@ -40,14 +40,18 @@ XRuntime是一个Rack的middleware,配合Redis用来分析Http Server每个URI
40
40
 
41
41
  收集数据 `config.ru`:
42
42
 
43
- use Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/")
43
+ ``` ruby
44
+ use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/") do |name, password|
45
+ name == "cui" and password == "hello"
46
+ end
47
+ ```
44
48
 
45
49
  查看数据 `config.ru`:
46
50
 
47
51
  ``` ruby
48
52
  run Rack::URLMap.new \
49
53
  "/" => Server.new,
50
- "/xruntime" => XRuntime::Server.new{|name, password|name == "cui" and password == "hello"}
54
+ "/xruntime" => XRuntime::Server.new
51
55
  ```
52
56
 
53
57
  ### Rails3
@@ -55,13 +59,15 @@ run Rack::URLMap.new \
55
59
  收集数据 `config/environment.rb`:
56
60
 
57
61
  ``` ruby
58
- config.middleware.insert_after Rack::Runtime, Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/")
62
+ config.middleware.insert_after Rack::Runtime, Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/") do |name, password|
63
+ name == "cui" and password == "hello"
64
+ end
59
65
  ```
60
66
 
61
- 查看数据 `config/route.rb`:
67
+ 查看数据 `config/routes.rb`:
62
68
 
63
69
  ``` ruby
64
- mount Rack::XRuntime.new{|name, password|name == "cui" and password == "hello"}, :at => "/xruntime"
70
+ mount Rack::XRuntime, :at => "/xruntime"
65
71
  ```
66
72
 
67
73
  ### Test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
@@ -1,11 +1,12 @@
1
1
  module XRuntime
2
2
  class Middleware
3
-
3
+ attr_accessor :auth
4
4
  # threshold => ms
5
- def initialize(app, threshold, redis)
5
+ def initialize(app, threshold, redis, &auth)
6
6
  @app = app
7
7
  @threshold = threshold.to_f
8
8
  @redis = redis
9
+ @auth = auth
9
10
  XRuntime.middleware = self
10
11
  end
11
12
 
@@ -1,11 +1,11 @@
1
1
  module XRuntime
2
2
  class Server
3
- def initialize(app=nil, &auth)
3
+ def initialize(app=nil)
4
4
  @server = lambda {|env|
5
5
  @req = Rack::Request.new(env)
6
6
  [200, {'Content-Type' => 'text/html'}, [Template.new(XRuntime.middleware.ds, :limit => (@req.params["limit"] ? @req.params["limit"].to_i : 20), :offset => @req.params["offset"].to_i).render]]
7
7
  }
8
- @server = Rack::Auth::Basic.new(@server, &auth) if auth
8
+ @server = Rack::Auth::Basic.new(@server, &XRuntime.middleware.auth) if XRuntime.middleware.auth
9
9
  end
10
10
 
11
11
  def call(env)
data/test/server.ru CHANGED
@@ -8,7 +8,9 @@ require "#{File.dirname(__FILE__)}/../lib/x_runtime"
8
8
  class Server < Sinatra::Base
9
9
  # use XRuntime::Middleware, 10, Redis.connect(:url => "redis://localhost:6380/")
10
10
  # XRuntime::Middleware is same as Rack::XRuntime
11
- use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/")
11
+ use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/") do |name, password|
12
+ name == "cui" and password == "hello"
13
+ end
12
14
 
13
15
  get /.*/ do
14
16
  # sleep(1)
@@ -20,4 +22,4 @@ end
20
22
  # Use with basic auth
21
23
  run Rack::URLMap.new \
22
24
  "/" => Server.new,
23
- "/xruntime" => XRuntime::Server.new{|name, password|name == "cui" and password == "hello"}
25
+ "/xruntime" => XRuntime::Server.new
data/x_runtime.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "x_runtime"
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["\u{5d14}\u{5ce5}"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: x_runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  segments:
137
137
  - 0
138
- hash: 336817792487171531
138
+ hash: -2051941527554950884
139
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  none: false
141
141
  requirements: