apitest 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +48 -9
- data/config/initializers/apitest.rb +1 -33
- data/lib/apitest.rb +37 -1
- data/lib/apitest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9c932efea1742c420d8d73ec4982d99ff9fb8ed
|
4
|
+
data.tar.gz: 96916744dcf87a1518ca7c5adefedcc9655b502a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345924cb41f29583ec7ca0f00788940dc88f80599d9f5a0f0fdc56a567d4678e2f401c11b238911b130c6f09f7a2a0dbe9268eb118bbdb784a6c50d7080b46bc
|
7
|
+
data.tar.gz: be819f5df9595df40196f32b53b9aa995c801c6a9cc57d7d779c45ebe4f2bba9f1ddf1105c6ca7c207b7db4e9c28160c0c64ad0cf5bc8275e36563e2ba2b3e90
|
data/README.md
CHANGED
@@ -1,28 +1,67 @@
|
|
1
1
|
# Apitest
|
2
2
|
Short description and motivation.
|
3
3
|
|
4
|
-
##
|
5
|
-
|
4
|
+
## Version
|
5
|
+
0.1.4
|
6
6
|
|
7
7
|
## Installation
|
8
|
-
|
8
|
+
添加如下代码到 Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
11
|
gem 'apitest'
|
12
12
|
```
|
13
13
|
|
14
|
-
|
14
|
+
执行:
|
15
|
+
```bash
|
16
|
+
$ bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
安装lsof
|
20
|
+
|
21
|
+
|
22
|
+
```bash
|
23
|
+
$ yum install lsof -y #CentOS
|
24
|
+
```
|
25
|
+
|
15
26
|
```bash
|
16
|
-
$
|
27
|
+
$ sudo apt-get install lsof -y #Ubuntu
|
17
28
|
```
|
18
29
|
|
19
|
-
Or install it yourself as:
|
20
30
|
```bash
|
21
|
-
$
|
31
|
+
$ brew install lsof #MacOS
|
32
|
+
```
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
约定的api目录如下:
|
37
|
+
```shell
|
38
|
+
├── controllers
|
39
|
+
│ ├── api
|
40
|
+
│ │ └── v1
|
41
|
+
│ │ ├── foo_controller.rb
|
42
|
+
│ │ ├── bar_controller.rb
|
43
|
+
│ │ └── v2
|
44
|
+
│ │ ├── foobar_controller.rb
|
45
|
+
│ │ ├── barfoo_controller.rb
|
46
|
+
```
|
47
|
+
|
48
|
+
mount apitest到指定url,比如:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
mount Apitest::Engine => "/apitest"
|
52
|
+
|
22
53
|
```
|
23
54
|
|
55
|
+
浏览器中访问apitest 的url
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
## TODO
|
61
|
+
- [ ] 可自定义api目录
|
62
|
+
|
24
63
|
## Contributing
|
25
|
-
|
64
|
+
|
26
65
|
|
27
66
|
## License
|
28
|
-
|
67
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
@@ -1,33 +1 @@
|
|
1
|
-
|
2
|
-
fork do
|
3
|
-
p 'Kill Apitest WebSocket Process ...'
|
4
|
-
`lsof -i :9527 |awk '$1 == "ruby" {print $2}' |xargs kill -9`
|
5
|
-
begin
|
6
|
-
class Reader < EventMachine::FileTail
|
7
|
-
def initialize(path, startpos=-1, &block)
|
8
|
-
super(path, startpos)
|
9
|
-
@buffer = BufferedTokenizer.new
|
10
|
-
@block = block
|
11
|
-
end
|
12
|
-
|
13
|
-
def receive_data(data)
|
14
|
-
@buffer.extract(data).each { |line| @block.call(line) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
filename = "#{Rails.root}/log/#{Rails.env}.log"
|
19
|
-
|
20
|
-
EventMachine.run do
|
21
|
-
WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => 9527) do |ws|
|
22
|
-
proc = Proc.new { |line|
|
23
|
-
ws.send Ansi::To::Html.new(line.strip).to_html.strip
|
24
|
-
}
|
25
|
-
EventMachine::file_tail(filename, Reader, &proc)
|
26
|
-
end
|
27
|
-
p 'Start Apitest WebSocket Process !'
|
28
|
-
end
|
29
|
-
rescue Exception => e
|
30
|
-
retry
|
31
|
-
end
|
32
|
-
end
|
33
|
-
)
|
1
|
+
Apitest.start_server_log_listen unless require("rails/commands/server")
|
data/lib/apitest.rb
CHANGED
@@ -10,5 +10,41 @@ require 'eventmachine-tail'
|
|
10
10
|
require 'websocket-eventmachine-server'
|
11
11
|
|
12
12
|
module Apitest
|
13
|
-
|
13
|
+
class Reader < EventMachine::FileTail
|
14
|
+
def initialize(path, startpos=-1, &block)
|
15
|
+
super(path, startpos)
|
16
|
+
@buffer = BufferedTokenizer.new
|
17
|
+
@block = block
|
18
|
+
end
|
19
|
+
|
20
|
+
def receive_data(data)
|
21
|
+
@buffer.extract(data).each { |line| @block.call(line) }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def self.start_server_log_listen
|
25
|
+
Process.detach(
|
26
|
+
fork do
|
27
|
+
p 'Kill Apitest WebSocket Process ...'
|
28
|
+
`lsof -i :9527 |awk '$1 == "ruby" {print $2}' |xargs kill -9`
|
29
|
+
begin
|
30
|
+
filename = "#{Rails.root}/log/#{Rails.env}.log"
|
31
|
+
|
32
|
+
EventMachine.run do
|
33
|
+
WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => 9527) do |ws|
|
34
|
+
proc = Proc.new { |line|
|
35
|
+
ws.send Ansi::To::Html.new(line.strip).to_html.strip
|
36
|
+
}
|
37
|
+
EventMachine::file_tail(filename, Reader, &proc)
|
38
|
+
end
|
39
|
+
p 'Start Apitest WebSocket Process !'
|
40
|
+
end
|
41
|
+
rescue Exception => e
|
42
|
+
retry
|
43
|
+
end
|
44
|
+
end
|
45
|
+
)
|
46
|
+
end
|
14
47
|
end
|
48
|
+
|
49
|
+
|
50
|
+
|
data/lib/apitest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apitest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kyuubi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|