yardstick 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.travis.yml +11 -16
  6. data/CONTRIBUTING.md +11 -0
  7. data/Gemfile +3 -59
  8. data/Gemfile.devtools +54 -0
  9. data/Guardfile +32 -0
  10. data/LICENSE +1 -1
  11. data/README.md +71 -55
  12. data/Rakefile +2 -7
  13. data/TODO +12 -0
  14. data/bin/yardstick +1 -0
  15. data/config/devtools.yml +2 -0
  16. data/config/flay.yml +2 -2
  17. data/config/flog.yml +1 -1
  18. data/config/mutant.yml +3 -0
  19. data/config/{site.reek → reek.yml} +31 -25
  20. data/config/rubocop.yml +49 -0
  21. data/config/yardstick.yml +31 -0
  22. data/lib/yardstick.rb +35 -15
  23. data/lib/yardstick/cli.rb +7 -7
  24. data/lib/yardstick/config.rb +176 -0
  25. data/lib/yardstick/document.rb +215 -0
  26. data/lib/yardstick/document_set.rb +21 -0
  27. data/lib/yardstick/measurement.rb +18 -145
  28. data/lib/yardstick/measurement_set.rb +2 -2
  29. data/lib/yardstick/parser.rb +61 -0
  30. data/lib/yardstick/processor.rb +21 -35
  31. data/lib/yardstick/rake/measurement.rb +7 -49
  32. data/lib/yardstick/rake/verify.rb +28 -55
  33. data/lib/yardstick/report_output.rb +57 -0
  34. data/lib/yardstick/rule.rb +64 -37
  35. data/lib/yardstick/rule_config.rb +56 -0
  36. data/lib/yardstick/rules/api_tag.rb +95 -0
  37. data/lib/yardstick/rules/example_tag.rb +33 -0
  38. data/lib/yardstick/rules/return_tag.rb +21 -0
  39. data/lib/yardstick/rules/summary.rb +87 -0
  40. data/lib/yardstick/version.rb +1 -1
  41. data/lib/yardstick/yard_ext.rb +1 -6
  42. data/spec/integration/yardstick/class_methods/measure_spec.rb +22 -0
  43. data/spec/integration/yardstick/class_methods/measure_string_spec.rb +20 -0
  44. data/spec/integration/yardstick/document/file_spec.rb +16 -0
  45. data/spec/integration/yardstick/document/line_spec.rb +25 -0
  46. data/spec/integration/yardstick/document/path_spec.rb +45 -0
  47. data/spec/integration/yardstick/processor/process_string_spec.rb +401 -0
  48. data/spec/integration/yardstick/rake/measurement_spec.rb +22 -0
  49. data/spec/integration/yardstick/rake/verify_spec.rb +19 -0
  50. data/spec/shared/measured_itself_behavior.rb +15 -0
  51. data/spec/spec_helper.rb +13 -26
  52. data/spec/support/document_mock.rb +16 -0
  53. data/spec/support/rules.rb +51 -0
  54. data/spec/unit/yardstick/class_methods/measure_spec.rb +31 -0
  55. data/spec/unit/yardstick/class_methods/measure_string_spec.rb +33 -0
  56. data/spec/unit/yardstick/cli_spec.rb +11 -8
  57. data/spec/unit/yardstick/config/class_methods/coerce_spec.rb +32 -0
  58. data/spec/unit/yardstick/config/for_rule_spec.rb +47 -0
  59. data/spec/unit/yardstick/config/initialize_spec.rb +21 -0
  60. data/spec/unit/yardstick/config/output_spec.rb +15 -0
  61. data/spec/unit/yardstick/config/output_writer_spec.rb +20 -0
  62. data/spec/unit/yardstick/config/path_spec.rb +13 -0
  63. data/spec/unit/yardstick/config/path_writer_spec.rb +11 -0
  64. data/spec/unit/yardstick/config/require_exact_threshold_predicate_spec.rb +19 -0
  65. data/spec/unit/yardstick/config/require_exact_threshold_writer_spec.rb +19 -0
  66. data/spec/unit/yardstick/config/set_defaults_spec.rb +42 -0
  67. data/spec/unit/yardstick/config/threshold_writer_spec.rb +15 -0
  68. data/spec/unit/yardstick/config/verbose_predicate_spec.rb +19 -0
  69. data/spec/unit/yardstick/config/verbose_writer_spec.rb +19 -0
  70. data/spec/unit/yardstick/document/api_predicate_spec.rb +25 -0
  71. data/spec/unit/yardstick/document/class_methods/measure_spec.rb +25 -0
  72. data/spec/unit/yardstick/document/class_methods/register_rule_spec.rb +19 -0
  73. data/spec/unit/yardstick/document/class_methods/registered_rules_spec.rb +9 -0
  74. data/spec/unit/yardstick/document/docstring_spec.rb +11 -0
  75. data/spec/unit/yardstick/document/file_spec.rb +14 -0
  76. data/spec/unit/yardstick/document/has_tag_predicate_spec.rb +15 -0
  77. data/spec/unit/yardstick/document/line_spec.rb +12 -0
  78. data/spec/unit/yardstick/document/null_tag/text_spec.rb +9 -0
  79. data/spec/unit/yardstick/document/null_tag/types_spec.rb +9 -0
  80. data/spec/unit/yardstick/document/path_spec.rb +12 -0
  81. data/spec/unit/yardstick/document/summary_text_spec.rb +23 -0
  82. data/spec/unit/yardstick/document/tag_text_spec.rb +17 -0
  83. data/spec/unit/yardstick/document/tag_types_spec.rb +18 -0
  84. data/spec/unit/yardstick/document/visibility_spec.rb +22 -0
  85. data/spec/unit/yardstick/document_set/measure_spec.rb +28 -0
  86. data/spec/unit/yardstick/measurement/description_spec.rb +12 -0
  87. data/spec/unit/yardstick/measurement/initialize_spec.rb +12 -0
  88. data/spec/unit/yardstick/measurement/ok_predicate_spec.rb +21 -0
  89. data/spec/unit/yardstick/measurement/puts_spec.rb +62 -0
  90. data/spec/unit/yardstick/measurement/skip_predicate_spec.rb +27 -0
  91. data/spec/unit/yardstick/measurement_set/coverage_spec.rb +23 -0
  92. data/spec/unit/yardstick/measurement_set/failed_spec.rb +28 -0
  93. data/spec/unit/yardstick/measurement_set/initialize_spec.rb +27 -0
  94. data/spec/unit/yardstick/measurement_set/puts_spec.rb +63 -0
  95. data/spec/unit/yardstick/measurement_set/successful_spec.rb +13 -0
  96. data/spec/unit/yardstick/measurement_set/total_spec.rb +12 -0
  97. data/spec/unit/yardstick/ordered_set/each_spec.rb +18 -0
  98. data/spec/unit/yardstick/ordered_set/empty_predicate_spec.rb +19 -0
  99. data/spec/unit/yardstick/ordered_set/include_predicate_spec.rb +21 -0
  100. data/spec/unit/yardstick/ordered_set/index_spec.rb +21 -0
  101. data/spec/unit/yardstick/ordered_set/left_shift_operator_spec.rb +16 -0
  102. data/spec/unit/yardstick/ordered_set/length_spec.rb +11 -0
  103. data/spec/unit/yardstick/ordered_set/merge_spec.rb +16 -0
  104. data/spec/unit/yardstick/parser/class_methods/parse_paths_spec.rb +28 -0
  105. data/spec/unit/yardstick/parser/class_methods/parse_string_spec.rb +28 -0
  106. data/spec/unit/yardstick/processor/process_spec.rb +17 -0
  107. data/spec/unit/yardstick/processor/process_string_spec.rb +17 -0
  108. data/spec/unit/yardstick/rake/measurement/initialize_spec.rb +64 -0
  109. data/spec/unit/yardstick/rake/measurement/yardstick_measure_spec.rb +22 -0
  110. data/spec/unit/yardstick/rake/verify/initialize_spec.rb +72 -0
  111. data/spec/unit/yardstick/rake/verify/verify_measurements_spec.rb +85 -0
  112. data/spec/unit/yardstick/report_output/class_methods/coerce_spec.rb +18 -0
  113. data/spec/unit/yardstick/report_output/initialize_spec.rb +11 -0
  114. data/spec/unit/yardstick/report_output/to_s_spec.rb +12 -0
  115. data/spec/unit/yardstick/report_output/write_spec.rb +31 -0
  116. data/spec/unit/yardstick/round_percentage_spec.rb +9 -0
  117. data/spec/unit/yardstick/rule/class_methods/coerce_spec.rb +21 -0
  118. data/spec/unit/yardstick/rule/class_methods/inherited_spec.rb +15 -0
  119. data/spec/unit/yardstick/rule/enabled_predicate_spec.rb +18 -0
  120. data/spec/unit/yardstick/rule/initialize_spec.rb +25 -0
  121. data/spec/unit/yardstick/rule/validatable_predicate_spec.rb +11 -0
  122. data/spec/unit/yardstick/rule_config/enabled_for_path_predicate_spec.rb +41 -0
  123. data/spec/unit/yardstick/rule_config/initialize_spec.rb +16 -0
  124. data/spec/unit/yardstick/rules/api_tag/inclusion/valid_predicate_spec.rb +27 -0
  125. data/spec/unit/yardstick/rules/api_tag/presence/valid_predicate_spec.rb +25 -0
  126. data/spec/unit/yardstick/rules/api_tag/private_method/valid_predicate_spec.rb +21 -0
  127. data/spec/unit/yardstick/rules/api_tag/private_method/validatable_predicate_spec.rb +21 -0
  128. data/spec/unit/yardstick/rules/api_tag/protected_method/valid_predicate_spec.rb +25 -0
  129. data/spec/unit/yardstick/rules/api_tag/protected_method/validatable_predicate_spec.rb +21 -0
  130. data/spec/unit/yardstick/rules/example_tag/valid_predicate_spec.rb +25 -0
  131. data/spec/unit/yardstick/rules/example_tag/validatable_predicate_spec.rb +32 -0
  132. data/spec/unit/yardstick/rules/return_tag/valid_predicate_spec.rb +21 -0
  133. data/spec/unit/yardstick/rules/summary/delimiter/valid_predicate_spec.rb +21 -0
  134. data/spec/unit/yardstick/rules/summary/length/valid_predicate_spec.rb +27 -0
  135. data/spec/unit/yardstick/rules/summary/presence/valid_predicate_spec.rb +21 -0
  136. data/spec/unit/yardstick/rules/summary/presence/validatable_predicate_spec.rb +21 -0
  137. data/spec/unit/yardstick/rules/summary/single_line/valid_predicate_spec.rb +21 -0
  138. data/yardstick.gemspec +7 -11
  139. metadata +222 -65
  140. data/.rvmrc +0 -1
  141. data/lib/yardstick/measurable.rb +0 -67
  142. data/lib/yardstick/method.rb +0 -113
  143. data/lib/yardstick/rule_set.rb +0 -22
  144. data/spec/support/config_alias.rb +0 -5
  145. data/spec/unit/yardstick/measurement_set_spec.rb +0 -266
  146. data/spec/unit/yardstick/measurement_spec.rb +0 -257
  147. data/spec/unit/yardstick/method_spec.rb +0 -357
  148. data/spec/unit/yardstick/rake/measurement_spec.rb +0 -175
  149. data/spec/unit/yardstick/rake/verify_spec.rb +0 -231
  150. data/spec/unit/yardstick/rule_spec.rb +0 -36
  151. data/spec/unit/yardstick_spec.rb +0 -71
  152. data/tasks/metrics/ci.rake +0 -9
  153. data/tasks/metrics/flay.rake +0 -53
  154. data/tasks/metrics/flog.rake +0 -44
  155. data/tasks/metrics/heckle.rake +0 -52
  156. data/tasks/metrics/metric_fu.rake +0 -31
  157. data/tasks/metrics/reek.rake +0 -21
  158. data/tasks/metrics/roodi.rake +0 -19
  159. data/tasks/metrics/yardstick.rake +0 -27
  160. data/tasks/spec.rake +0 -64
  161. 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
- # @yield [task]
53
- # yield to self
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 = name
64
- @require_exact_threshold = true
65
- @path = 'lib/**/*.rb'
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(@path)
103
- self.class.round_percentage(measurements.coverage * 100)
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
- if @threshold.nil?
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
- total_coverage = self.total_coverage
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
- total_coverage = self.total_coverage
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
- # Round percentage to 1/10th of a percent
128
+ # Checks if total coverage is lower than the threshold
163
129
  #
164
- # @param [Float] percentage
165
- # the percentage to round
130
+ # @return [Boolean]
131
+ # true if current coverage is lower
166
132
  #
167
- # @return [Float]
168
- # the rounded percentage
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 self.round_percentage(percentage)
172
- (percentage * 10).ceil / 10.0
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
@@ -1,65 +1,92 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Yardstick
4
-
5
- # A constraint on the docs
4
+ # Base class of every rule
5
+ #
6
+ # @abstract
6
7
  class Rule
8
+ extend Forwardable
7
9
 
8
- # Return a Rule instance
9
- #
10
- # @param [#to_str] description
11
- # the description of the Rule
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
- # @yield []
14
- # the measurement for the rule
25
+ # @param [Class] subclass
26
+ # class that is inheriting from this class
15
27
  #
16
- # @return [Rule]
17
- # the rule instance
28
+ # @return [undefined]
18
29
  #
19
30
  # @api private
20
- def initialize(description, &block)
21
- @description = description.to_str
22
- @block = block
31
+ def self.inherited(subclass)
32
+ Document.register_rule(subclass)
23
33
  end
34
+ private_class_method :inherited
24
35
 
25
- # Return a Measurement for a docstring
36
+ # Makes a new instance of rule using given config
26
37
  #
27
- # @param [YARD::Docstring] docstring
28
- # the docstring to measure
38
+ # @param [Yardstick::Document] document
39
+ # document that will be measured
40
+ # @param [Yardstick::Config] config
41
+ # a configuration
29
42
  #
30
- # @return [Measurement]
31
- # the measurement
43
+ # @return [Yardstick::Rule]
32
44
  #
33
45
  # @api private
34
- def measure(docstring)
35
- Measurement.new(@description, docstring, &@block)
46
+ def self.coerce(document, config)
47
+ new(document, config.for_rule(self))
36
48
  end
37
49
 
38
- # Test if Rule is equal to another rule
50
+ # Return document that current rule is using
39
51
  #
40
- # @example
41
- # rule == equal_rule # => true
52
+ # @return [Document]
42
53
  #
43
- # @param [Rule] other
44
- # the other Rule
54
+ # @api private
55
+ attr_reader :document
56
+
57
+ # Initializes a rule
45
58
  #
46
- # @return [Boolean]
47
- # true if the Rule is equal to the other, false if not
59
+ # @param [Yardstick::Document] document
60
+ # @param [Yardstick::RuleConfig] config
61
+ # rule configuration
62
+ #
63
+ # @return [Yardstick::Rule]
48
64
  #
49
- # @api semipublic
50
- def eql?(other)
51
- @description.eql?(other.instance_variable_get(:@description))
65
+ # @api private
66
+ def initialize(document, config = RuleConfig.new)
67
+ @document = document
68
+ @config = config
52
69
  end
53
70
 
54
- # Return hash identifier for the Rule
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 [Integer]
57
- # the hash identifier
75
+ # @return [Boolean]
76
+ # true if enabled
58
77
  #
59
78
  # @api private
60
- def hash
61
- @description.hash
79
+ def enabled?
80
+ @config.enabled_for_path?(@document.path)
62
81
  end
63
82
 
64
- end # class Rule
65
- end # module Yardstick
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