nginx_utils 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -69,6 +69,7 @@ module NginxUtils
69
69
  first = true
70
70
  @params = default_params.merge(options)
71
71
  flags = @params.keys
72
+ flags.delete(:script_log) if options[:debug] && options[:script_log].nil?
72
73
  else
73
74
  first = false
74
75
  flags = options.select{|k,v| @params[k] != v}.keys
@@ -10,26 +10,29 @@ module NginxUtils
10
10
 
11
11
  req = Net::HTTP::Get.new(path)
12
12
  res = Net::HTTP.start(host, port){|http| http.request(req)}
13
- parse res
13
+ parse res.body.split("\n").map{|l| l.split}
14
14
  end
15
15
 
16
16
  private
17
- def parse(response)
18
- status = response.body.split("\n")
19
- formexp(status[0], status[2].split, status[3].split)
17
+ def parse(spbody)
18
+ formexp([
19
+ spbody[0].last,
20
+ spbody[2],
21
+ spbody[3].select{|i| /^[0-9]*$/ =~ i}
22
+ ].flatten.map{|i| i.to_i})
20
23
  rescue
21
24
  raise "Parse error"
22
25
  end
23
26
 
24
- def formexp(ac_line, server_line, rww_line)
27
+ def formexp(args)
25
28
  {
26
- active_connections: ac_line.split(":")[1].to_i,
27
- accepts: server_line[0].to_i,
28
- handled: server_line[1].to_i,
29
- requests: server_line[2].to_i,
30
- reading: rww_line[1].to_i,
31
- writing: rww_line[3].to_i,
32
- waiting: rww_line[5].to_i
29
+ active_connections: args[0],
30
+ accepts: args[1],
31
+ handled: args[2],
32
+ requests: args[3],
33
+ reading: args[4],
34
+ writing: args[5],
35
+ waiting: args[6]
33
36
  }
34
37
  end
35
38
  end
@@ -1,3 +1,3 @@
1
1
  module NginxUtils
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -18,20 +18,20 @@ describe "NginxUtils::Status" do
18
18
 
19
19
  describe ".parse" do
20
20
  it "should return status hash" do
21
- response = double("http response mock", body: body)
22
- expect(NginxUtils::Status.send(:parse, response)).to eq(status)
21
+ spbody = body.split("\n").map{|l| l.split}
22
+ expect(NginxUtils::Status.send(:parse, spbody)).to eq(status)
23
23
  end
24
24
 
25
25
  it "should generate an exception if parse failed" do
26
- response = double("http response mock", body: "invalid content")
27
- expect(proc{NginxUtils::Status.send(:parse, response)}).to raise_error(RuntimeError, "Parse error")
26
+ spbody = "invalid content".split("\n").map{|l| l.split}
27
+ expect(proc{NginxUtils::Status.send(:parse, spbody)}).to raise_error(RuntimeError, "Parse error")
28
28
  end
29
29
  end
30
30
 
31
31
  describe ".formexp" do
32
32
  it "should return status hash with format" do
33
- args = body.split("\n")
34
- expect(NginxUtils::Status.send(:formexp, args[0], args[2].split, args[3].split)).to eq(status)
33
+ args = [1, 4, 5, 51, 1, 3, 2]
34
+ expect(NginxUtils::Status.send(:formexp, args)).to eq(status)
35
35
  end
36
36
  end
37
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nginx_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
118
  version: '0'
119
119
  segments:
120
120
  - 0
121
- hash: -1389210587237094459
121
+ hash: -3985509799625259397
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  none: false
124
124
  requirements:
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -1389210587237094459
130
+ hash: -3985509799625259397
131
131
  requirements: []
132
132
  rubyforge_project:
133
133
  rubygems_version: 1.8.25