yardstick 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +4 -0
- data/.ruby-gemset +1 -0
- data/.travis.yml +11 -16
- data/CONTRIBUTING.md +11 -0
- data/Gemfile +3 -59
- data/Gemfile.devtools +54 -0
- data/Guardfile +32 -0
- data/LICENSE +1 -1
- data/README.md +71 -55
- data/Rakefile +2 -7
- data/TODO +12 -0
- data/bin/yardstick +1 -0
- data/config/devtools.yml +2 -0
- data/config/flay.yml +2 -2
- data/config/flog.yml +1 -1
- data/config/mutant.yml +3 -0
- data/config/{site.reek → reek.yml} +31 -25
- data/config/rubocop.yml +49 -0
- data/config/yardstick.yml +31 -0
- data/lib/yardstick.rb +35 -15
- data/lib/yardstick/cli.rb +7 -7
- data/lib/yardstick/config.rb +176 -0
- data/lib/yardstick/document.rb +215 -0
- data/lib/yardstick/document_set.rb +21 -0
- data/lib/yardstick/measurement.rb +18 -145
- data/lib/yardstick/measurement_set.rb +2 -2
- data/lib/yardstick/parser.rb +61 -0
- data/lib/yardstick/processor.rb +21 -35
- data/lib/yardstick/rake/measurement.rb +7 -49
- data/lib/yardstick/rake/verify.rb +28 -55
- data/lib/yardstick/report_output.rb +57 -0
- data/lib/yardstick/rule.rb +64 -37
- data/lib/yardstick/rule_config.rb +56 -0
- data/lib/yardstick/rules/api_tag.rb +95 -0
- data/lib/yardstick/rules/example_tag.rb +33 -0
- data/lib/yardstick/rules/return_tag.rb +21 -0
- data/lib/yardstick/rules/summary.rb +87 -0
- data/lib/yardstick/version.rb +1 -1
- data/lib/yardstick/yard_ext.rb +1 -6
- data/spec/integration/yardstick/class_methods/measure_spec.rb +22 -0
- data/spec/integration/yardstick/class_methods/measure_string_spec.rb +20 -0
- data/spec/integration/yardstick/document/file_spec.rb +16 -0
- data/spec/integration/yardstick/document/line_spec.rb +25 -0
- data/spec/integration/yardstick/document/path_spec.rb +45 -0
- data/spec/integration/yardstick/processor/process_string_spec.rb +401 -0
- data/spec/integration/yardstick/rake/measurement_spec.rb +22 -0
- data/spec/integration/yardstick/rake/verify_spec.rb +19 -0
- data/spec/shared/measured_itself_behavior.rb +15 -0
- data/spec/spec_helper.rb +13 -26
- data/spec/support/document_mock.rb +16 -0
- data/spec/support/rules.rb +51 -0
- data/spec/unit/yardstick/class_methods/measure_spec.rb +31 -0
- data/spec/unit/yardstick/class_methods/measure_string_spec.rb +33 -0
- data/spec/unit/yardstick/cli_spec.rb +11 -8
- data/spec/unit/yardstick/config/class_methods/coerce_spec.rb +32 -0
- data/spec/unit/yardstick/config/for_rule_spec.rb +47 -0
- data/spec/unit/yardstick/config/initialize_spec.rb +21 -0
- data/spec/unit/yardstick/config/output_spec.rb +15 -0
- data/spec/unit/yardstick/config/output_writer_spec.rb +20 -0
- data/spec/unit/yardstick/config/path_spec.rb +13 -0
- data/spec/unit/yardstick/config/path_writer_spec.rb +11 -0
- data/spec/unit/yardstick/config/require_exact_threshold_predicate_spec.rb +19 -0
- data/spec/unit/yardstick/config/require_exact_threshold_writer_spec.rb +19 -0
- data/spec/unit/yardstick/config/set_defaults_spec.rb +42 -0
- data/spec/unit/yardstick/config/threshold_writer_spec.rb +15 -0
- data/spec/unit/yardstick/config/verbose_predicate_spec.rb +19 -0
- data/spec/unit/yardstick/config/verbose_writer_spec.rb +19 -0
- data/spec/unit/yardstick/document/api_predicate_spec.rb +25 -0
- data/spec/unit/yardstick/document/class_methods/measure_spec.rb +25 -0
- data/spec/unit/yardstick/document/class_methods/register_rule_spec.rb +19 -0
- data/spec/unit/yardstick/document/class_methods/registered_rules_spec.rb +9 -0
- data/spec/unit/yardstick/document/docstring_spec.rb +11 -0
- data/spec/unit/yardstick/document/file_spec.rb +14 -0
- data/spec/unit/yardstick/document/has_tag_predicate_spec.rb +15 -0
- data/spec/unit/yardstick/document/line_spec.rb +12 -0
- data/spec/unit/yardstick/document/null_tag/text_spec.rb +9 -0
- data/spec/unit/yardstick/document/null_tag/types_spec.rb +9 -0
- data/spec/unit/yardstick/document/path_spec.rb +12 -0
- data/spec/unit/yardstick/document/summary_text_spec.rb +23 -0
- data/spec/unit/yardstick/document/tag_text_spec.rb +17 -0
- data/spec/unit/yardstick/document/tag_types_spec.rb +18 -0
- data/spec/unit/yardstick/document/visibility_spec.rb +22 -0
- data/spec/unit/yardstick/document_set/measure_spec.rb +28 -0
- data/spec/unit/yardstick/measurement/description_spec.rb +12 -0
- data/spec/unit/yardstick/measurement/initialize_spec.rb +12 -0
- data/spec/unit/yardstick/measurement/ok_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/measurement/puts_spec.rb +62 -0
- data/spec/unit/yardstick/measurement/skip_predicate_spec.rb +27 -0
- data/spec/unit/yardstick/measurement_set/coverage_spec.rb +23 -0
- data/spec/unit/yardstick/measurement_set/failed_spec.rb +28 -0
- data/spec/unit/yardstick/measurement_set/initialize_spec.rb +27 -0
- data/spec/unit/yardstick/measurement_set/puts_spec.rb +63 -0
- data/spec/unit/yardstick/measurement_set/successful_spec.rb +13 -0
- data/spec/unit/yardstick/measurement_set/total_spec.rb +12 -0
- data/spec/unit/yardstick/ordered_set/each_spec.rb +18 -0
- data/spec/unit/yardstick/ordered_set/empty_predicate_spec.rb +19 -0
- data/spec/unit/yardstick/ordered_set/include_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/ordered_set/index_spec.rb +21 -0
- data/spec/unit/yardstick/ordered_set/left_shift_operator_spec.rb +16 -0
- data/spec/unit/yardstick/ordered_set/length_spec.rb +11 -0
- data/spec/unit/yardstick/ordered_set/merge_spec.rb +16 -0
- data/spec/unit/yardstick/parser/class_methods/parse_paths_spec.rb +28 -0
- data/spec/unit/yardstick/parser/class_methods/parse_string_spec.rb +28 -0
- data/spec/unit/yardstick/processor/process_spec.rb +17 -0
- data/spec/unit/yardstick/processor/process_string_spec.rb +17 -0
- data/spec/unit/yardstick/rake/measurement/initialize_spec.rb +64 -0
- data/spec/unit/yardstick/rake/measurement/yardstick_measure_spec.rb +22 -0
- data/spec/unit/yardstick/rake/verify/initialize_spec.rb +72 -0
- data/spec/unit/yardstick/rake/verify/verify_measurements_spec.rb +85 -0
- data/spec/unit/yardstick/report_output/class_methods/coerce_spec.rb +18 -0
- data/spec/unit/yardstick/report_output/initialize_spec.rb +11 -0
- data/spec/unit/yardstick/report_output/to_s_spec.rb +12 -0
- data/spec/unit/yardstick/report_output/write_spec.rb +31 -0
- data/spec/unit/yardstick/round_percentage_spec.rb +9 -0
- data/spec/unit/yardstick/rule/class_methods/coerce_spec.rb +21 -0
- data/spec/unit/yardstick/rule/class_methods/inherited_spec.rb +15 -0
- data/spec/unit/yardstick/rule/enabled_predicate_spec.rb +18 -0
- data/spec/unit/yardstick/rule/initialize_spec.rb +25 -0
- data/spec/unit/yardstick/rule/validatable_predicate_spec.rb +11 -0
- data/spec/unit/yardstick/rule_config/enabled_for_path_predicate_spec.rb +41 -0
- data/spec/unit/yardstick/rule_config/initialize_spec.rb +16 -0
- data/spec/unit/yardstick/rules/api_tag/inclusion/valid_predicate_spec.rb +27 -0
- data/spec/unit/yardstick/rules/api_tag/presence/valid_predicate_spec.rb +25 -0
- data/spec/unit/yardstick/rules/api_tag/private_method/valid_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/api_tag/private_method/validatable_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/api_tag/protected_method/valid_predicate_spec.rb +25 -0
- data/spec/unit/yardstick/rules/api_tag/protected_method/validatable_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/example_tag/valid_predicate_spec.rb +25 -0
- data/spec/unit/yardstick/rules/example_tag/validatable_predicate_spec.rb +32 -0
- data/spec/unit/yardstick/rules/return_tag/valid_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/summary/delimiter/valid_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/summary/length/valid_predicate_spec.rb +27 -0
- data/spec/unit/yardstick/rules/summary/presence/valid_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/summary/presence/validatable_predicate_spec.rb +21 -0
- data/spec/unit/yardstick/rules/summary/single_line/valid_predicate_spec.rb +21 -0
- data/yardstick.gemspec +7 -11
- metadata +222 -65
- data/.rvmrc +0 -1
- data/lib/yardstick/measurable.rb +0 -67
- data/lib/yardstick/method.rb +0 -113
- data/lib/yardstick/rule_set.rb +0 -22
- data/spec/support/config_alias.rb +0 -5
- data/spec/unit/yardstick/measurement_set_spec.rb +0 -266
- data/spec/unit/yardstick/measurement_spec.rb +0 -257
- data/spec/unit/yardstick/method_spec.rb +0 -357
- data/spec/unit/yardstick/rake/measurement_spec.rb +0 -175
- data/spec/unit/yardstick/rake/verify_spec.rb +0 -231
- data/spec/unit/yardstick/rule_spec.rb +0 -36
- data/spec/unit/yardstick_spec.rb +0 -71
- data/tasks/metrics/ci.rake +0 -9
- data/tasks/metrics/flay.rake +0 -53
- data/tasks/metrics/flog.rake +0 -44
- data/tasks/metrics/heckle.rake +0 -52
- data/tasks/metrics/metric_fu.rake +0 -31
- data/tasks/metrics/reek.rake +0 -21
- data/tasks/metrics/roodi.rake +0 -19
- data/tasks/metrics/yardstick.rake +0 -27
- data/tasks/spec.rake +0 -64
- data/tasks/yard.rake +0 -11
@@ -11,34 +11,6 @@ module Yardstick
|
|
11
11
|
# A rake task for verifying the doc thresholds
|
12
12
|
class Verify < ::Rake::TaskLib
|
13
13
|
|
14
|
-
# Set the threshold
|
15
|
-
#
|
16
|
-
# @return [undefined]
|
17
|
-
#
|
18
|
-
# @api public
|
19
|
-
attr_writer :threshold
|
20
|
-
|
21
|
-
# Specify if the threshold should match the coverage
|
22
|
-
#
|
23
|
-
# @return [undefined]
|
24
|
-
#
|
25
|
-
# @api public
|
26
|
-
attr_writer :require_exact_threshold
|
27
|
-
|
28
|
-
# List of paths to measure
|
29
|
-
#
|
30
|
-
# @return [undefined]
|
31
|
-
#
|
32
|
-
# @api public
|
33
|
-
attr_writer :path
|
34
|
-
|
35
|
-
# Specify if the coverage summary should be displayed
|
36
|
-
#
|
37
|
-
# @return [undefined]
|
38
|
-
#
|
39
|
-
# @api public
|
40
|
-
attr_writer :verbose
|
41
|
-
|
42
14
|
# Initialize a Verify task
|
43
15
|
#
|
44
16
|
# @example
|
@@ -46,26 +18,22 @@ module Yardstick
|
|
46
18
|
# task.threshold = 100
|
47
19
|
# end
|
48
20
|
#
|
21
|
+
# @param [Hash] options
|
22
|
+
# optional configuration
|
49
23
|
# @param [Symbol] name
|
50
24
|
# optional task name
|
51
25
|
#
|
52
|
-
# @
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# @yieldparam [Yardstick::Rake::Verify] task
|
56
|
-
# the verification task
|
26
|
+
# @yieldparam [Yardstick::Config] config
|
27
|
+
# the config object
|
57
28
|
#
|
58
29
|
# @return [Yardstick::Rake::Verify] task
|
59
30
|
# the verification task instance
|
60
31
|
#
|
61
32
|
# @api public
|
62
|
-
def initialize(name = :verify_measurements)
|
63
|
-
@name
|
64
|
-
@
|
65
|
-
@
|
66
|
-
@verbose = true
|
67
|
-
|
68
|
-
yield self
|
33
|
+
def initialize(name = :verify_measurements, options = {}, &block)
|
34
|
+
@name = name
|
35
|
+
@config = Config.coerce(options, &block)
|
36
|
+
@threshold = @config.threshold
|
69
37
|
|
70
38
|
assert_threshold
|
71
39
|
define
|
@@ -85,7 +53,7 @@ module Yardstick
|
|
85
53
|
#
|
86
54
|
# @api public
|
87
55
|
def verify_measurements
|
88
|
-
puts "YARD-Coverage: #{total_coverage}% (threshold: #{@threshold}%)" if verbose
|
56
|
+
puts "YARD-Coverage: #{total_coverage}% (threshold: #{@threshold}%)" if @config.verbose?
|
89
57
|
assert_meets_threshold
|
90
58
|
assert_matches_threshold
|
91
59
|
end
|
@@ -99,8 +67,8 @@ module Yardstick
|
|
99
67
|
#
|
100
68
|
# @api private
|
101
69
|
def total_coverage
|
102
|
-
measurements = Yardstick.measure(@
|
103
|
-
|
70
|
+
measurements = Yardstick.measure(@config)
|
71
|
+
Yardstick.round_percentage(measurements.coverage * 100)
|
104
72
|
end
|
105
73
|
|
106
74
|
private
|
@@ -124,7 +92,7 @@ module Yardstick
|
|
124
92
|
#
|
125
93
|
# @api private
|
126
94
|
def assert_threshold
|
127
|
-
|
95
|
+
unless @threshold
|
128
96
|
raise 'threshold must be set'
|
129
97
|
end
|
130
98
|
end
|
@@ -138,8 +106,7 @@ module Yardstick
|
|
138
106
|
#
|
139
107
|
# @api private
|
140
108
|
def assert_meets_threshold
|
141
|
-
|
142
|
-
if total_coverage < @threshold
|
109
|
+
if lower_coverage?
|
143
110
|
raise "YARD-Coverage must be at least #{@threshold}% but was #{total_coverage}%"
|
144
111
|
end
|
145
112
|
end
|
@@ -153,23 +120,29 @@ module Yardstick
|
|
153
120
|
#
|
154
121
|
# @api private
|
155
122
|
def assert_matches_threshold
|
156
|
-
|
157
|
-
if @require_exact_threshold && total_coverage > @threshold
|
123
|
+
if @config.require_exact_threshold? && higher_coverage?
|
158
124
|
raise "YARD-Coverage has increased above the threshold of #{@threshold}% to #{total_coverage}%. You should update your threshold value."
|
159
125
|
end
|
160
126
|
end
|
161
127
|
|
162
|
-
#
|
128
|
+
# Checks if total coverage is lower than the threshold
|
163
129
|
#
|
164
|
-
# @
|
165
|
-
#
|
130
|
+
# @return [Boolean]
|
131
|
+
# true if current coverage is lower
|
166
132
|
#
|
167
|
-
# @
|
168
|
-
|
133
|
+
# @api private
|
134
|
+
def lower_coverage?
|
135
|
+
total_coverage < @threshold
|
136
|
+
end
|
137
|
+
|
138
|
+
# Checks if total coverage is higher than the threshold
|
139
|
+
#
|
140
|
+
# @return [Boolean]
|
141
|
+
# true if current coverage is higher
|
169
142
|
#
|
170
143
|
# @api private
|
171
|
-
def
|
172
|
-
|
144
|
+
def higher_coverage?
|
145
|
+
total_coverage > @threshold
|
173
146
|
end
|
174
147
|
|
175
148
|
end # class Verify
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yardstick
|
4
|
+
|
5
|
+
# Handles writing reports
|
6
|
+
class ReportOutput
|
7
|
+
|
8
|
+
# Coerces string path into proper output object
|
9
|
+
#
|
10
|
+
# @param [String, Pathname] target
|
11
|
+
# path of the output
|
12
|
+
#
|
13
|
+
# @return [Yardstick::ReportOutput]
|
14
|
+
#
|
15
|
+
# @api private
|
16
|
+
def self.coerce(target)
|
17
|
+
new(Pathname(target))
|
18
|
+
end
|
19
|
+
|
20
|
+
# Initializes ReportOutput instance
|
21
|
+
#
|
22
|
+
# @param [Pathname] target
|
23
|
+
#
|
24
|
+
# @return [undefined]
|
25
|
+
#
|
26
|
+
# @api private
|
27
|
+
def initialize(target)
|
28
|
+
@target = target
|
29
|
+
end
|
30
|
+
|
31
|
+
# Open up a report for writing
|
32
|
+
#
|
33
|
+
# @yield [io]
|
34
|
+
# yield to an object that responds to #puts
|
35
|
+
#
|
36
|
+
# @yieldparam [#puts] io
|
37
|
+
# the object that responds to #puts
|
38
|
+
#
|
39
|
+
# @return [undefined]
|
40
|
+
#
|
41
|
+
# @api private
|
42
|
+
def write(&block)
|
43
|
+
@target.dirname.mkpath
|
44
|
+
@target.open('w', &block)
|
45
|
+
end
|
46
|
+
|
47
|
+
# @see [Pathname#to_s]
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
#
|
51
|
+
# @api private
|
52
|
+
def to_s
|
53
|
+
@target.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/yardstick/rule.rb
CHANGED
@@ -1,65 +1,92 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Yardstick
|
4
|
-
|
5
|
-
#
|
4
|
+
# Base class of every rule
|
5
|
+
#
|
6
|
+
# @abstract
|
6
7
|
class Rule
|
8
|
+
extend Forwardable
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
class << self
|
11
|
+
# Description of the rule
|
12
|
+
#
|
13
|
+
# This is shown when a rule is invalid
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
#
|
17
|
+
# @api private
|
18
|
+
attr_accessor :description
|
19
|
+
|
20
|
+
private :description=
|
21
|
+
end
|
22
|
+
|
23
|
+
# Register rule in Document
|
12
24
|
#
|
13
|
-
# @
|
14
|
-
#
|
25
|
+
# @param [Class] subclass
|
26
|
+
# class that is inheriting from this class
|
15
27
|
#
|
16
|
-
# @return [
|
17
|
-
# the rule instance
|
28
|
+
# @return [undefined]
|
18
29
|
#
|
19
30
|
# @api private
|
20
|
-
def
|
21
|
-
|
22
|
-
@block = block
|
31
|
+
def self.inherited(subclass)
|
32
|
+
Document.register_rule(subclass)
|
23
33
|
end
|
34
|
+
private_class_method :inherited
|
24
35
|
|
25
|
-
#
|
36
|
+
# Makes a new instance of rule using given config
|
26
37
|
#
|
27
|
-
# @param [
|
28
|
-
#
|
38
|
+
# @param [Yardstick::Document] document
|
39
|
+
# document that will be measured
|
40
|
+
# @param [Yardstick::Config] config
|
41
|
+
# a configuration
|
29
42
|
#
|
30
|
-
# @return [
|
31
|
-
# the measurement
|
43
|
+
# @return [Yardstick::Rule]
|
32
44
|
#
|
33
45
|
# @api private
|
34
|
-
def
|
35
|
-
|
46
|
+
def self.coerce(document, config)
|
47
|
+
new(document, config.for_rule(self))
|
36
48
|
end
|
37
49
|
|
38
|
-
#
|
50
|
+
# Return document that current rule is using
|
39
51
|
#
|
40
|
-
# @
|
41
|
-
# rule == equal_rule # => true
|
52
|
+
# @return [Document]
|
42
53
|
#
|
43
|
-
# @
|
44
|
-
|
54
|
+
# @api private
|
55
|
+
attr_reader :document
|
56
|
+
|
57
|
+
# Initializes a rule
|
45
58
|
#
|
46
|
-
# @
|
47
|
-
#
|
59
|
+
# @param [Yardstick::Document] document
|
60
|
+
# @param [Yardstick::RuleConfig] config
|
61
|
+
# rule configuration
|
62
|
+
#
|
63
|
+
# @return [Yardstick::Rule]
|
48
64
|
#
|
49
|
-
# @api
|
50
|
-
def
|
51
|
-
@
|
65
|
+
# @api private
|
66
|
+
def initialize(document, config = RuleConfig.new)
|
67
|
+
@document = document
|
68
|
+
@config = config
|
52
69
|
end
|
53
70
|
|
54
|
-
|
71
|
+
def_delegators :@document, :has_tag?, :api?, :tag_types, :tag_text, :summary_text, :visibility
|
72
|
+
|
73
|
+
# Checks if rule is enabled in current context
|
55
74
|
#
|
56
|
-
# @return [
|
57
|
-
#
|
75
|
+
# @return [Boolean]
|
76
|
+
# true if enabled
|
58
77
|
#
|
59
78
|
# @api private
|
60
|
-
def
|
61
|
-
@
|
79
|
+
def enabled?
|
80
|
+
@config.enabled_for_path?(@document.path)
|
62
81
|
end
|
63
82
|
|
64
|
-
|
65
|
-
|
83
|
+
# Checks if the rule is validatable for given document
|
84
|
+
#
|
85
|
+
# @return [Boolean]
|
86
|
+
#
|
87
|
+
# @api private
|
88
|
+
def validatable?
|
89
|
+
true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yardstick
|
4
|
+
# Config class for rules
|
5
|
+
#
|
6
|
+
# It is used to check if document should be validated or not.
|
7
|
+
#
|
8
|
+
class RuleConfig
|
9
|
+
METHOD_SEPARATOR = /\#|\./.freeze
|
10
|
+
|
11
|
+
# Initializes new instance of rule config
|
12
|
+
#
|
13
|
+
# @param [Hash] options
|
14
|
+
# optional configuration
|
15
|
+
#
|
16
|
+
# @return [Yardstick::RuleConfig]
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
def initialize(options = {})
|
20
|
+
@enabled = options.fetch(:enabled, true)
|
21
|
+
@exclude = options.fetch(:exclude, [])
|
22
|
+
end
|
23
|
+
|
24
|
+
# Checks if given path should be checked using this rule
|
25
|
+
#
|
26
|
+
# @param [String] path
|
27
|
+
# document path, e.g "Foo::Bar#baz"
|
28
|
+
#
|
29
|
+
# @return [Boolean]
|
30
|
+
# true if path should be checked
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
def enabled_for_path?(path)
|
34
|
+
@enabled && !exclude?(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# Checks if given path is in exclude list
|
40
|
+
#
|
41
|
+
# If exact match fails then checks if the method class is in the exclude
|
42
|
+
# list.
|
43
|
+
#
|
44
|
+
# @param [String] path
|
45
|
+
# document path
|
46
|
+
#
|
47
|
+
# @return [Boolean]
|
48
|
+
# true if path is in the exclude list
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
def exclude?(path)
|
52
|
+
@exclude.include?(path) ||
|
53
|
+
@exclude.include?(path.split(METHOD_SEPARATOR).first)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yardstick
|
4
|
+
module Rules
|
5
|
+
# Rules related to @api tag
|
6
|
+
#
|
7
|
+
class ApiTag
|
8
|
+
# Checks if @api tag is present
|
9
|
+
#
|
10
|
+
class Presence < Rule
|
11
|
+
self.description = 'The @api tag should be specified'
|
12
|
+
|
13
|
+
# @see class description
|
14
|
+
#
|
15
|
+
# @return [Boolean]
|
16
|
+
# true if valid
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
def valid?
|
20
|
+
has_tag?('api')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Checks if @api tag is a public, semipublic or private
|
25
|
+
#
|
26
|
+
class Inclusion < Rule
|
27
|
+
VALID_VALUES = %w[ public semipublic private ].freeze
|
28
|
+
|
29
|
+
self.description = 'The @api tag must be either public, semipublic or private'
|
30
|
+
|
31
|
+
# @see class description
|
32
|
+
#
|
33
|
+
# @return [Boolean]
|
34
|
+
# true if valid
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
def valid?
|
38
|
+
VALID_VALUES.include?(tag_text('api'))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Checks if protected method has correct @api visibility
|
43
|
+
#
|
44
|
+
class ProtectedMethod < Rule
|
45
|
+
self.description = 'A method with protected visibility must have an @api tag of semipublic or private'
|
46
|
+
|
47
|
+
# @see Rule::validatable?
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
# true if method visibility is protected
|
51
|
+
#
|
52
|
+
# @api private
|
53
|
+
def validatable?
|
54
|
+
visibility == :protected
|
55
|
+
end
|
56
|
+
|
57
|
+
# @see class description
|
58
|
+
#
|
59
|
+
# @return [Boolean]
|
60
|
+
# true if api tag is semipublic or private
|
61
|
+
#
|
62
|
+
# @api private
|
63
|
+
def valid?
|
64
|
+
api?(%w[ semipublic private ])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Checks if private method has correct @api visibility
|
69
|
+
#
|
70
|
+
class PrivateMethod < Rule
|
71
|
+
self.description = 'A method with private visibility must have an @api tag of private'
|
72
|
+
|
73
|
+
# @see Rule::validatable?
|
74
|
+
#
|
75
|
+
# @return [Boolean]
|
76
|
+
# true method visibility is private
|
77
|
+
#
|
78
|
+
# @api private
|
79
|
+
def validatable?
|
80
|
+
visibility == :private
|
81
|
+
end
|
82
|
+
|
83
|
+
# @see class description
|
84
|
+
#
|
85
|
+
# @return [Boolean]
|
86
|
+
# true if api tag is private
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
def valid?
|
90
|
+
api?(%w[ private ])
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|