had 0.1.2 → 0.1.3
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/README.md +12 -8
- data/lib/had/collector.rb +91 -1
- data/lib/had/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5a234619e796d00f776e724aa52d8a0cc61b01c
|
4
|
+
data.tar.gz: 5f63a7cffb3842ef0acbdd03f2b2715bc763e541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2166be48e66cb2438fd2dafc5518a5bdc432c9c1dd8eca8d1a489d6048dde0a62950b8e2fcc049dc6c398802f740752b9b8ac021db7414de18e4329fb339765
|
7
|
+
data.tar.gz: 22d1b5aa63e2d67df4674b68965ca9d308eca8ebf7c6a686990fcaaa597e61e51fdc3c5242724087280f2c6b4a0a0797c257abd7cc3f59998e7cce8a9cd092bb
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ If necessary, add `require "had"` to your `spec/spec_helper.rb` file
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
Before start you need to setup environment.
|
24
|
-
`export APP_ROOT=/path/to/your/application`
|
24
|
+
`export APP_ROOT=/path/to/your/application`
|
25
25
|
|
26
26
|
By default `had` is not active (this may be configured!). To activate it, run `rspec` with
|
27
27
|
|
@@ -32,19 +32,23 @@ Documentation will be put into your application's `/doc` folder
|
|
32
32
|
### Sample controller action
|
33
33
|
|
34
34
|
```ruby
|
35
|
+
params do
|
36
|
+
required(:book).schema do
|
37
|
+
required(:author).filled(:str?) # This is params description
|
38
|
+
required(:title).filled(:str?) # Can be empty
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
# @description creates Category from given parameters
|
36
43
|
# description text may be multiline
|
37
|
-
# @param
|
38
|
-
# @param
|
44
|
+
# @param book[author] required String | You can use this params
|
45
|
+
# @param book[title] in which order | if you did't using dry-validation
|
39
46
|
# param text may also be multiline
|
40
47
|
def call(params)
|
41
48
|
# action code
|
42
49
|
end
|
43
50
|
```
|
44
51
|
|
45
|
-
Description param text is started with `@description` and may be multiline.
|
46
|
-
Each param text is started with `@param` and first word will be param name, then optionally `required`, then optionally type (`Integer`, `String` etc), and finally param description, which may be multiline as well.
|
47
|
-
|
48
52
|
### Sample rspec test
|
49
53
|
|
50
54
|
```ruby
|
@@ -133,7 +137,7 @@ end
|
|
133
137
|
```
|
134
138
|
|
135
139
|
1. Fork it
|
136
|
-
2. Create your feature branch (`git checkout -b
|
140
|
+
2. Create your feature branch (`git checkout -b my_new_feature`)
|
137
141
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
138
|
-
4. Push to the branch (`git push origin
|
142
|
+
4. Push to the branch (`git push origin my_new_feature`)
|
139
143
|
5. Create new Pull Request
|
data/lib/had/collector.rb
CHANGED
@@ -305,10 +305,17 @@ module Had
|
|
305
305
|
# returns params action comments
|
306
306
|
# example TODO
|
307
307
|
def get_action_params(controller, action)
|
308
|
-
|
308
|
+
# This way using for getting params from parsing dry-validation schemes
|
309
|
+
params_lines = get_params_lines(controller, action)
|
310
|
+
comments = get_params_comments(params_lines)
|
311
|
+
|
312
|
+
return comments unless comments.empty?
|
309
313
|
|
314
|
+
# This way using for getting params form comments
|
315
|
+
comment_lines = get_action_comments(controller, action)
|
310
316
|
comments_raw = []
|
311
317
|
has_param = false
|
318
|
+
|
312
319
|
comment_lines.each do |line|
|
313
320
|
if line.match(/\s*#\s*@param/) # @param id required Integer blah blah
|
314
321
|
has_param = true
|
@@ -342,6 +349,89 @@ module Had
|
|
342
349
|
comments
|
343
350
|
end
|
344
351
|
|
352
|
+
# return params comments parsed from params_lines
|
353
|
+
# example TODO
|
354
|
+
def get_params_comments(params_lines)
|
355
|
+
parent_params = nil
|
356
|
+
comments = []
|
357
|
+
|
358
|
+
params_lines.each do |line|
|
359
|
+
if line.match(/\s*(required|optional)\(:\w*\)\.\w*/) &&
|
360
|
+
!line.match(/\s*(required|optional)\(:\w*\)\.\w*\s(do)/)
|
361
|
+
|
362
|
+
name = line.split('(')[1].split(')')[0].tr(':', '')
|
363
|
+
required = line.match(/\s(required|optional)/).to_s.strip
|
364
|
+
description = line.match(/\s*#/) ? line.split('#').last.strip : '--'
|
365
|
+
|
366
|
+
type = if line.match(/\s*(required|optional)\(:\w*\)\.\w*\(:\w*\?\)/)
|
367
|
+
line.split('(')[2].split(')')[0].tr(':?', '')
|
368
|
+
else
|
369
|
+
'Any'
|
370
|
+
end
|
371
|
+
|
372
|
+
name = "#{parent_params}[#{name}]" unless parent_params.nil?
|
373
|
+
|
374
|
+
comments << {
|
375
|
+
name: name,
|
376
|
+
required: required,
|
377
|
+
type: type,
|
378
|
+
description: description
|
379
|
+
}
|
380
|
+
end
|
381
|
+
|
382
|
+
parent_params = false if line.match(/\s(end)/)
|
383
|
+
|
384
|
+
if line.match(/\s*(required|optional)\(:\w*\)\.\w*\s(do)/)
|
385
|
+
str = line.split('(')[1].split(')')[0].tr(':', '')
|
386
|
+
|
387
|
+
if parent_params.nil?
|
388
|
+
parent_params = str
|
389
|
+
else
|
390
|
+
parent_params = "#{parent_params}[#{str}]"
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
comments
|
396
|
+
rescue Exception
|
397
|
+
[]
|
398
|
+
end
|
399
|
+
|
400
|
+
# returns dry-validations params lines
|
401
|
+
# example TODO
|
402
|
+
def get_params_lines(controller, action)
|
403
|
+
lines = File.readlines(File.join(Had.root, 'app', 'controllers', "#{controller.underscore}", "#{action.underscore}.rb"))
|
404
|
+
params_lines = []
|
405
|
+
params_begins = false
|
406
|
+
ends_left = 0
|
407
|
+
|
408
|
+
lines.each_with_index do |line, index|
|
409
|
+
if line.match(/\s*params do/)
|
410
|
+
params_lines << line
|
411
|
+
params_begins = true
|
412
|
+
ends_left += 1
|
413
|
+
|
414
|
+
next
|
415
|
+
end
|
416
|
+
|
417
|
+
if params_begins
|
418
|
+
params_lines << line
|
419
|
+
|
420
|
+
if line.match(/\s*do/)
|
421
|
+
ends_left += 1
|
422
|
+
elsif line.match(/\s*end/)
|
423
|
+
ends_left -= 1
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
params_begins = false if ends_left <= 0
|
428
|
+
end
|
429
|
+
|
430
|
+
params_lines
|
431
|
+
rescue Exception
|
432
|
+
{}
|
433
|
+
end
|
434
|
+
|
345
435
|
def cleanup_header(key)
|
346
436
|
key.to_s.sub(/^HTTP_/, '').underscore.split('_').map(&:capitalize).join('-')
|
347
437
|
end
|
data/lib/had/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: had
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nsheremet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coderay
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.6.11
|
119
119
|
signing_key:
|
120
120
|
specification_version: 4
|
121
121
|
summary: Generates API documentation for integration tests written with RSpec for
|