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
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yardstick
|
4
|
+
|
5
|
+
# A set of yardstick documents
|
6
|
+
class DocumentSet < OrderedSet
|
7
|
+
|
8
|
+
# Measure documents using given config
|
9
|
+
#
|
10
|
+
# @return [Yardstick::MeasurementSet]
|
11
|
+
# a collection of measurements
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def measure(config)
|
15
|
+
each_with_object(MeasurementSet.new) do |document, set|
|
16
|
+
set.merge(Document.measure(document, config))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -4,48 +4,22 @@ module Yardstick
|
|
4
4
|
|
5
5
|
# A measurement given a constraint on the docs
|
6
6
|
class Measurement
|
7
|
-
|
8
|
-
# Return the Measurement description
|
9
|
-
#
|
10
|
-
# @example
|
11
|
-
# measurement.description # => "The description"
|
12
|
-
#
|
13
|
-
# @return [String]
|
14
|
-
# the description
|
15
|
-
#
|
16
|
-
# @api public
|
17
|
-
attr_reader :description
|
18
|
-
|
19
|
-
# Return the method docstring
|
20
|
-
#
|
21
|
-
# @return [YARD::Docstring]
|
22
|
-
#
|
23
|
-
# @api private
|
24
|
-
attr_reader :docstring
|
25
|
-
protected :docstring
|
26
|
-
|
27
7
|
# Return a Measurement instance
|
28
8
|
#
|
29
9
|
# @example
|
30
|
-
# measurement = Measurement.new(
|
31
|
-
#
|
32
|
-
# @param [#to_str] description
|
33
|
-
# the measurement description
|
34
|
-
# @param [YARD::Docstring] docstring
|
35
|
-
# the docstring to measure
|
10
|
+
# measurement = Measurement.new(document, rule)
|
36
11
|
#
|
37
|
-
# @
|
38
|
-
#
|
12
|
+
# @param [Yardstick::Document] document
|
13
|
+
# @param [Yardstick::Rule] rule
|
39
14
|
#
|
40
15
|
# @return [Yardstick::Measurement]
|
41
16
|
# the measurement instance
|
42
17
|
#
|
43
18
|
# @api public
|
44
|
-
def initialize(
|
45
|
-
@
|
46
|
-
@
|
47
|
-
@
|
48
|
-
@result = measure
|
19
|
+
def initialize(rule)
|
20
|
+
@document = rule.document
|
21
|
+
@rule = rule
|
22
|
+
@result = measure
|
49
23
|
end
|
50
24
|
|
51
25
|
# Return true if the measurement was successful
|
@@ -80,22 +54,6 @@ module Yardstick
|
|
80
54
|
@result == :skip
|
81
55
|
end
|
82
56
|
|
83
|
-
# Return true if the measurement is not implemented
|
84
|
-
#
|
85
|
-
# @example Measurement not implemented
|
86
|
-
# measurement.todo? # => true
|
87
|
-
#
|
88
|
-
# @example Measurement implemented
|
89
|
-
# measurement.todo? # => false
|
90
|
-
#
|
91
|
-
# @return [Boolean]
|
92
|
-
# true if the measurement is not implemented, false if not
|
93
|
-
#
|
94
|
-
# @api public
|
95
|
-
def todo?
|
96
|
-
@result == :todo
|
97
|
-
end
|
98
|
-
|
99
57
|
# Warns the results the measurement if it was not successful
|
100
58
|
#
|
101
59
|
# @example
|
@@ -109,121 +67,36 @@ module Yardstick
|
|
109
67
|
# @api public
|
110
68
|
def puts(io = $stdout)
|
111
69
|
unless ok?
|
112
|
-
io.puts("#{file}:#{line}: #{path}: #{description}")
|
70
|
+
io.puts("#{@document.file}:#{@document.line}: #{@document.path}: #{description}")
|
113
71
|
end
|
114
72
|
end
|
115
73
|
|
116
|
-
#
|
74
|
+
# Return the Measurement description
|
117
75
|
#
|
118
76
|
# @example
|
119
|
-
# measurement
|
120
|
-
#
|
121
|
-
# @param [Yardstick::Measurement] other
|
122
|
-
# the other Measurement
|
123
|
-
#
|
124
|
-
# @return [Boolean]
|
125
|
-
# true if the Measurement is equal to the other, false if not
|
126
|
-
#
|
127
|
-
# @api semipublic
|
128
|
-
def eql?(other)
|
129
|
-
other.kind_of?(self.class) &&
|
130
|
-
description.eql?(other.description) &&
|
131
|
-
docstring.eql?(other.docstring)
|
132
|
-
end
|
133
|
-
|
134
|
-
# Return hash identifier for the Measurement
|
77
|
+
# measurement.description # => "The description"
|
135
78
|
#
|
136
|
-
# @return [
|
137
|
-
# the
|
79
|
+
# @return [String]
|
80
|
+
# the description
|
138
81
|
#
|
139
|
-
# @api
|
140
|
-
def
|
141
|
-
|
82
|
+
# @api public
|
83
|
+
def description
|
84
|
+
@rule.class.description
|
142
85
|
end
|
143
86
|
|
144
87
|
private
|
145
88
|
|
146
|
-
# Measure the
|
89
|
+
# Measure the document using the rule provided to the constructor
|
147
90
|
#
|
148
91
|
# @return [Boolean, Symbol]
|
149
92
|
# true if the test is successful, false if not
|
150
|
-
# :todo if the test is not implemented
|
151
93
|
# :skip if the test does not apply
|
152
94
|
#
|
153
95
|
# @api private
|
154
96
|
def measure
|
155
|
-
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# The code object for the docstring
|
161
|
-
#
|
162
|
-
# @return [YARD::CodeObjects::Base]
|
163
|
-
# the code object
|
164
|
-
#
|
165
|
-
# @api private
|
166
|
-
def object
|
167
|
-
docstring.object
|
168
|
-
end
|
169
|
-
|
170
|
-
# The filename for the code
|
171
|
-
#
|
172
|
-
# @return [Pathname]
|
173
|
-
# the filename
|
174
|
-
#
|
175
|
-
# @api private
|
176
|
-
def file
|
177
|
-
Pathname(object.file)
|
97
|
+
return :skip if !@rule.enabled? || !@rule.validatable?
|
98
|
+
@rule.valid?
|
178
99
|
end
|
179
100
|
|
180
|
-
# The line number for the code
|
181
|
-
#
|
182
|
-
# @return [Integer]
|
183
|
-
# the line number
|
184
|
-
#
|
185
|
-
# @api private
|
186
|
-
def line
|
187
|
-
object.line
|
188
|
-
end
|
189
|
-
|
190
|
-
# The class and method name for the code
|
191
|
-
#
|
192
|
-
# @return [String]
|
193
|
-
# the class and method name
|
194
|
-
#
|
195
|
-
# @api private
|
196
|
-
def path
|
197
|
-
object.path
|
198
|
-
end
|
199
|
-
|
200
|
-
module UtilityMethods #:nodoc:
|
201
|
-
private
|
202
|
-
|
203
|
-
# Throw a :skip measurement message to the caller
|
204
|
-
#
|
205
|
-
# This method allows you to short-circuit measurement methods when
|
206
|
-
# the measurement does not apply due to specific object states.
|
207
|
-
#
|
208
|
-
# @return [undefined]
|
209
|
-
#
|
210
|
-
# @api private
|
211
|
-
def skip
|
212
|
-
throw :measurement, :skip
|
213
|
-
end
|
214
|
-
|
215
|
-
# Throw a :todo measurement message to the caller
|
216
|
-
#
|
217
|
-
# This method allows you to short-circuit measurement methods when
|
218
|
-
# the measurement is not implemented.
|
219
|
-
#
|
220
|
-
# @return [undefined]
|
221
|
-
#
|
222
|
-
# @api private
|
223
|
-
def todo
|
224
|
-
throw :measurement, :todo
|
225
|
-
end
|
226
|
-
|
227
|
-
end # module UtilityMethods
|
228
101
|
end # class Measurement
|
229
102
|
end # module Yardstick
|
@@ -85,7 +85,7 @@ module Yardstick
|
|
85
85
|
#
|
86
86
|
# @api private
|
87
87
|
def puts_summary(io)
|
88
|
-
io.puts("\n#{[
|
88
|
+
io.puts("\n#{[coverage_text, successful_text, failed_text, total_text].join(' ')}")
|
89
89
|
end
|
90
90
|
|
91
91
|
# The text for the coverage percentage to include in the summary
|
@@ -95,7 +95,7 @@ module Yardstick
|
|
95
95
|
#
|
96
96
|
# @api private
|
97
97
|
def coverage_text
|
98
|
-
'YARD-Coverage: %.1f%%' % (coverage * 100)
|
98
|
+
'YARD-Coverage: %.1f%%' % Yardstick.round_percentage(coverage * 100)
|
99
99
|
end
|
100
100
|
|
101
101
|
# The text for the successful measurements to include in the summary
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Yardstick
|
4
|
+
|
5
|
+
# Parses files and strings using YARD
|
6
|
+
class Parser
|
7
|
+
|
8
|
+
# Measure files specified in the paths
|
9
|
+
#
|
10
|
+
# @return [Array<Document>]
|
11
|
+
# a collection of parsed documents
|
12
|
+
#
|
13
|
+
# @api private
|
14
|
+
def self.parse_paths(paths)
|
15
|
+
YARD.parse(paths, [], YARD::Logger::ERROR)
|
16
|
+
documents
|
17
|
+
end
|
18
|
+
|
19
|
+
# Measure string provided
|
20
|
+
#
|
21
|
+
# @param [#to_str] string
|
22
|
+
# the string to measure
|
23
|
+
#
|
24
|
+
# @return [Array<Document>]
|
25
|
+
# a collection of parsed documents
|
26
|
+
#
|
27
|
+
# @api private
|
28
|
+
def self.parse_string(string)
|
29
|
+
YARD.parse_string(string.to_str)
|
30
|
+
documents
|
31
|
+
end
|
32
|
+
|
33
|
+
# Coerces method objects into documents
|
34
|
+
#
|
35
|
+
# @return [Yardstick::DocumentSet]
|
36
|
+
#
|
37
|
+
# @api private
|
38
|
+
def self.documents
|
39
|
+
method_objects.each_with_object(DocumentSet.new) do |method_object, set|
|
40
|
+
set << Document.new(method_object.docstring)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
private_class_method :documents
|
44
|
+
|
45
|
+
# Return method objects in YARD registry
|
46
|
+
#
|
47
|
+
# @return [Array<YARD::CodeObjects::MethodObject>]
|
48
|
+
# a collection of method objects
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
def self.method_objects
|
52
|
+
YARD::Registry.all(:method).sort_by do |method_object|
|
53
|
+
[method_object.file, method_object.line]
|
54
|
+
end
|
55
|
+
ensure
|
56
|
+
YARD::Registry.clear
|
57
|
+
end
|
58
|
+
private_class_method :method_objects
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/yardstick/processor.rb
CHANGED
@@ -5,64 +5,50 @@ module Yardstick
|
|
5
5
|
# Handle procesing a docstring or path of files
|
6
6
|
class Processor
|
7
7
|
|
8
|
-
#
|
8
|
+
# Initializes new Processor instance
|
9
9
|
#
|
10
|
-
# @param [
|
11
|
-
#
|
10
|
+
# @param [Yardstick::Config] config
|
11
|
+
# a configuration
|
12
12
|
#
|
13
|
-
# @return [
|
14
|
-
# a collection of measurements
|
13
|
+
# @return [undefined]
|
15
14
|
#
|
16
15
|
# @api private
|
17
|
-
def
|
18
|
-
|
19
|
-
measurements
|
16
|
+
def initialize(config)
|
17
|
+
@config = config
|
20
18
|
end
|
21
19
|
|
22
|
-
# Measure
|
23
|
-
#
|
24
|
-
# @param [#to_str] string
|
25
|
-
# the string to measure
|
20
|
+
# Measure files specified in the config
|
26
21
|
#
|
27
22
|
# @return [Yardstick::MeasurementSet]
|
28
23
|
# a collection of measurements
|
29
24
|
#
|
30
25
|
# @api private
|
31
|
-
def
|
32
|
-
|
33
|
-
measurements
|
26
|
+
def process
|
27
|
+
Parser.parse_paths(paths).measure(@config)
|
34
28
|
end
|
35
29
|
|
36
|
-
# Measure
|
30
|
+
# Measure string provided
|
31
|
+
#
|
32
|
+
# @param [#to_str] string
|
33
|
+
# the string to measure
|
37
34
|
#
|
38
35
|
# @return [Yardstick::MeasurementSet]
|
39
36
|
# a collection of measurements
|
40
37
|
#
|
41
38
|
# @api private
|
42
|
-
def
|
43
|
-
|
44
|
-
method_objects.each do |method_object|
|
45
|
-
measurements.merge(method_object.docstring.measure)
|
46
|
-
end
|
47
|
-
measurements
|
39
|
+
def process_string(string)
|
40
|
+
Parser.parse_string(string).measure(@config)
|
48
41
|
end
|
49
42
|
|
50
|
-
|
43
|
+
private
|
44
|
+
|
45
|
+
# Return config's possible paths
|
51
46
|
#
|
52
|
-
# @return [Array<
|
53
|
-
# a collection of method objects
|
47
|
+
# @return [Array<String>]
|
54
48
|
#
|
55
49
|
# @api private
|
56
|
-
def
|
57
|
-
|
58
|
-
[ method_object.file, method_object.line ]
|
59
|
-
end
|
60
|
-
ensure
|
61
|
-
YARD::Registry.clear
|
62
|
-
end
|
63
|
-
|
64
|
-
class << self
|
65
|
-
private :measurements, :method_objects
|
50
|
+
def paths
|
51
|
+
Array(@config.path).map(&:to_s)
|
66
52
|
end
|
67
53
|
|
68
54
|
end # class Processor
|
@@ -12,25 +12,6 @@ module Yardstick
|
|
12
12
|
# A rake task for measuring docs in a set of files
|
13
13
|
class Measurement < ::Rake::TaskLib
|
14
14
|
|
15
|
-
# List of paths to measure
|
16
|
-
#
|
17
|
-
# @return [undefined]
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
attr_writer :path
|
21
|
-
|
22
|
-
# The path to the file where the measurements will be written
|
23
|
-
#
|
24
|
-
# @param [String, Pathname] output
|
25
|
-
# optional output path for measurements
|
26
|
-
#
|
27
|
-
# @return [undefined]
|
28
|
-
#
|
29
|
-
# @api public
|
30
|
-
def output=(output)
|
31
|
-
@output = Pathname(output)
|
32
|
-
end
|
33
|
-
|
34
15
|
# Initializes a Measurement task
|
35
16
|
#
|
36
17
|
# @example
|
@@ -39,23 +20,16 @@ module Yardstick
|
|
39
20
|
# @param [Symbol] name
|
40
21
|
# optional task name
|
41
22
|
#
|
42
|
-
# @
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# @yieldparam [Yardstick::Rake::Measurement] task
|
46
|
-
# the measurement task
|
23
|
+
# @yieldparam [Yardstick::Config] config
|
24
|
+
# the config object
|
47
25
|
#
|
48
26
|
# @return [Yardstick::Rake::Measurement]
|
49
27
|
# the measurement task
|
50
28
|
#
|
51
29
|
# @api public
|
52
|
-
def initialize(name = :yardstick_measure)
|
53
|
-
@name
|
54
|
-
@
|
55
|
-
|
56
|
-
self.output = 'measurements/report.txt'
|
57
|
-
|
58
|
-
yield self if block_given?
|
30
|
+
def initialize(name = :yardstick_measure, options = {}, &block)
|
31
|
+
@name = name
|
32
|
+
@config = Config.coerce(options, &block)
|
59
33
|
|
60
34
|
define
|
61
35
|
end
|
@@ -69,7 +43,7 @@ module Yardstick
|
|
69
43
|
#
|
70
44
|
# @api public
|
71
45
|
def yardstick_measure
|
72
|
-
|
46
|
+
@config.output.write { |io| Yardstick.measure(@config).puts(io) }
|
73
47
|
end
|
74
48
|
|
75
49
|
private
|
@@ -80,26 +54,10 @@ module Yardstick
|
|
80
54
|
#
|
81
55
|
# @api private
|
82
56
|
def define
|
83
|
-
desc "Measure docs in #{@path} with yardstick"
|
57
|
+
desc "Measure docs in #{@config.path} with yardstick"
|
84
58
|
task(@name) { yardstick_measure }
|
85
59
|
end
|
86
60
|
|
87
|
-
# Open up a report for writing
|
88
|
-
#
|
89
|
-
# @yield [io]
|
90
|
-
# yield to an object that responds to #puts
|
91
|
-
#
|
92
|
-
# @yieldparam [#puts] io
|
93
|
-
# the object that responds to #puts
|
94
|
-
#
|
95
|
-
# @return [undefined]
|
96
|
-
#
|
97
|
-
# @api private
|
98
|
-
def write_report(&block)
|
99
|
-
@output.dirname.mkpath
|
100
|
-
@output.open('w', &block)
|
101
|
-
end
|
102
|
-
|
103
61
|
end # class Measurement
|
104
62
|
end # module Rake
|
105
63
|
end # module Yardstick
|