crapidocs 0.1.4 → 0.2.0
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.
- checksums.yaml +4 -4
- data/lib/crapidocs/session.rb +18 -6
- data/lib/crapidocs.rb +39 -5
- 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: e9e7d0c00bd7671481cbe59831d7df48d8b140f8
|
4
|
+
data.tar.gz: 0f841c50048160d4fe3e708c47ac449e3a32f8ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c904b31276f460fe9e2c375fe66968a7ed40e5e5bef1003da6f080ffdd936328fe0959408e9642405738c7aeaacddfc6e1b798ec6e59ddcb3a9ce14724115b
|
7
|
+
data.tar.gz: 2d3db67aa421291cdc2ae1896d594f7a23925c320a24a0ed24ba531c83a0f0cc3a844e6647ba971009ef758ce6d47869f6e6c85d81f28e644d8e27d846d8204c
|
data/lib/crapidocs/session.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module CrapiDocs
|
2
2
|
class Session
|
3
|
+
attr_reader :actions
|
4
|
+
|
3
5
|
def initialize(pattern)
|
4
6
|
@pattern = pattern
|
5
7
|
@actions = {}
|
@@ -17,8 +19,7 @@ module CrapiDocs
|
|
17
19
|
request: {
|
18
20
|
method: method,
|
19
21
|
body: env['rack.input'].string,
|
20
|
-
headers: env
|
21
|
-
uri: uri
|
22
|
+
headers: clean_headers(env)
|
22
23
|
},
|
23
24
|
response: {
|
24
25
|
status: status,
|
@@ -27,7 +28,7 @@ module CrapiDocs
|
|
27
28
|
}
|
28
29
|
}
|
29
30
|
|
30
|
-
path =
|
31
|
+
path = clean_path(uri.path)
|
31
32
|
@actions[path] ||= {}
|
32
33
|
@actions[path][method] ||= []
|
33
34
|
@actions[path][method] << action
|
@@ -56,6 +57,13 @@ module CrapiDocs
|
|
56
57
|
parse_body(res[:body])
|
57
58
|
end
|
58
59
|
|
60
|
+
def merge(sessions)
|
61
|
+
sessions = [sessions] unless sessions.is_a?(Array)
|
62
|
+
@actions = sessions.reduce(@actions) do |a, session|
|
63
|
+
a.deep_merge(session.actions)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
59
67
|
private
|
60
68
|
|
61
69
|
def parse_body(body)
|
@@ -72,9 +80,13 @@ module CrapiDocs
|
|
72
80
|
params
|
73
81
|
end
|
74
82
|
|
75
|
-
def
|
83
|
+
def clean_headers(headers)
|
84
|
+
headers.delete_if { |k, _v| k =~ /^(sinatra|rack)\./ }
|
85
|
+
end
|
86
|
+
|
87
|
+
def clean_path(path)
|
76
88
|
last = nil
|
77
|
-
|
89
|
+
path.split('/').reject(&:blank?).reduce('') do |cleaned, part|
|
78
90
|
part = ":#{last.singularize}_id" if part =~ /^\d+$/
|
79
91
|
part = ':token' if tokenish?(part)
|
80
92
|
last = part
|
@@ -83,7 +95,7 @@ module CrapiDocs
|
|
83
95
|
end
|
84
96
|
|
85
97
|
def tokenish?(s)
|
86
|
-
s =~ /\d+/ && s =~ /[a-zA-Z]+/ && s.length >= 10
|
98
|
+
(s =~ /\d+/ && s =~ /[a-zA-Z]+/ && s.length >= 10) == true
|
87
99
|
end
|
88
100
|
|
89
101
|
def relevant?(uri)
|
data/lib/crapidocs.rb
CHANGED
@@ -16,8 +16,10 @@ module Rack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
module CrapiDocs
|
19
|
-
VERSION = [0,
|
19
|
+
VERSION = [0, 2, 0]
|
20
20
|
TEMPLATE_DIR = File.expand_path('../..', __FILE__) + '/templates'
|
21
|
+
PARALLEL = ENV['PARALLEL_TEST_GROUPS'] && defined?(ParallelTests)
|
22
|
+
SESSION_FILE_PREFIX = 'crapi-session.'
|
21
23
|
|
22
24
|
class << self
|
23
25
|
attr_reader :session
|
@@ -26,9 +28,10 @@ module CrapiDocs
|
|
26
28
|
VERSION.join('.')
|
27
29
|
end
|
28
30
|
|
29
|
-
def start(pattern, target = './doc/api.md')
|
31
|
+
def start(pattern, target = './doc/api.md', tmp = './tmp')
|
30
32
|
@session = Session.new(pattern)
|
31
33
|
@target = target
|
34
|
+
@tmp = tmp
|
32
35
|
end
|
33
36
|
|
34
37
|
def purge
|
@@ -40,14 +43,45 @@ module CrapiDocs
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def done
|
46
|
+
handle_parallel if CrapiDocs::PARALLEL
|
43
47
|
formatter = Formatter.new(@session)
|
44
|
-
|
48
|
+
write_docs(formatter.to_md)
|
45
49
|
end
|
46
50
|
|
47
51
|
private
|
48
52
|
|
49
|
-
def
|
50
|
-
|
53
|
+
def handle_parallel
|
54
|
+
return write_session unless ParallelTests.first_process?
|
55
|
+
ParallelTests.wait_for_other_processes_to_finish
|
56
|
+
@session.merge(load_sessions)
|
57
|
+
end
|
58
|
+
|
59
|
+
def session_file
|
60
|
+
test_num = ENV['TEST_ENV_NUMBER'] || '1'
|
61
|
+
format('%s/%s%s', @tmp, SESSION_FILE_PREFIX, test_num)
|
62
|
+
end
|
63
|
+
|
64
|
+
def write_session
|
65
|
+
write_file(session_file, Marshal.dump(@session))
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_sessions
|
69
|
+
glob = "#{@tmp}/#{SESSION_FILE_PREFIX}*"
|
70
|
+
Dir[glob].map { |f| load_session(f) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def load_session(file)
|
74
|
+
data = File.open(file).read
|
75
|
+
File.unlink(file)
|
76
|
+
Marshal.load(data)
|
77
|
+
end
|
78
|
+
|
79
|
+
def write_docs(data)
|
80
|
+
write_file(@target, data)
|
81
|
+
end
|
82
|
+
|
83
|
+
def write_file(file, data)
|
84
|
+
File.open(file, 'w') { |f| f.write(data) }
|
51
85
|
end
|
52
86
|
end
|
53
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crapidocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Holly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Generate decent API documentation from RSpec API tests.
|
14
14
|
email: mikejholly@gmail.com
|