sidekiq-statsd 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/README.md +8 -4
- data/lib/sidekiq/statsd/client.rb +10 -10
- data/lib/sidekiq/statsd/server_middleware.rb +8 -9
- data/lib/sidekiq/statsd/version.rb +1 -1
- data/spec/sidekiq/statsd/client_spec.rb +6 -6
- data/spec/spec_helper.rb +1 -0
- data/vendor/ruby/1.9.1/bin/yard +1 -1
- data/vendor/ruby/1.9.1/bin/yardoc +1 -1
- data/vendor/ruby/1.9.1/bin/yri +1 -1
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/default_factory.rb +176 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/default_tag.rb +12 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/directives.rb +595 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/library.rb +630 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/option_tag.rb +12 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/overload_tag.rb +65 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/ref_tag.rb +7 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/ref_tag_list.rb +27 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/tag.rb +57 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/lib/yard/tags/tag_format_error.rb +6 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/default_factory_spec.rb +152 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/default_tag_spec.rb +11 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/directives_spec.rb +436 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/library_spec.rb +34 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/overload_tag_spec.rb +53 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/spec/tags/ref_tag_list_spec.rb +53 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/example.erb +11 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/index.erb +3 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/option.erb +24 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/overload.erb +14 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/see.erb +8 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/html/tag.erb +20 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/setup.rb +55 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/example.erb +12 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/index.erb +1 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/option.erb +20 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/overload.erb +19 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/see.erb +11 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/default/tags/text/tag.erb +13 -0
- data/vendor/ruby/1.9.1/gems/yard-0.8.6.1/templates/guide/tags/html/setup.rb +8 -0
- metadata +34 -4
@@ -0,0 +1,595 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module YARD
|
4
|
+
module Tags
|
5
|
+
# The base directive class. Subclass this class to create a custom
|
6
|
+
# directive, registering it with {Library.define_directive}. Directive
|
7
|
+
# classes are executed via the {#call} method, which perform all directive
|
8
|
+
# processing on the object.
|
9
|
+
#
|
10
|
+
# If processing occurs within a handler, the {#handler} attribute is
|
11
|
+
# available to access more information about parsing context and state.
|
12
|
+
# Handlers are only available when parsing from {Parser::SourceParser},
|
13
|
+
# not when parsing directly from {DocstringParser}. If the docstring is
|
14
|
+
# attached to an object declaration, {#object} will be set and available
|
15
|
+
# to modify the generated code object directly. Note that both of these
|
16
|
+
# attributes may be nil, and directives should test their existence
|
17
|
+
# before attempting to use them.
|
18
|
+
#
|
19
|
+
# @abstract Subclasses should implement {#call}.
|
20
|
+
# @see Library.define_directive
|
21
|
+
# @since 0.8.0
|
22
|
+
class Directive
|
23
|
+
# @return [Tag] the meta-data tag containing data input to the directive
|
24
|
+
attr_accessor :tag
|
25
|
+
|
26
|
+
# Set this field to replace the directive definition inside of a docstring
|
27
|
+
# with arbitrary text. For instance, the {MacroDirective} uses this field
|
28
|
+
# to expand its macro data in place of the call to a +@!macro+.
|
29
|
+
#
|
30
|
+
# @return [String] the text to expand in the original docstring in place
|
31
|
+
# of this directive definition.
|
32
|
+
# @return [nil] if no expansion should take place for this directive
|
33
|
+
attr_accessor :expanded_text
|
34
|
+
|
35
|
+
# @return [DocstringParser] the parser that is parsing all tag
|
36
|
+
# information out of the docstring
|
37
|
+
attr_accessor :parser
|
38
|
+
|
39
|
+
# @!attribute [r] object
|
40
|
+
# @return [CodeObjects::Base, nil] the object the parent docstring is
|
41
|
+
# attached to. May be nil.
|
42
|
+
def object; parser.object end
|
43
|
+
|
44
|
+
# @!attribute [r] handler
|
45
|
+
# @return [Handlers::Base, nil] the handler object the docstring parser
|
46
|
+
# might be attached to. May be nil. Only available when parsing
|
47
|
+
# through {Parser::SourceParser}.
|
48
|
+
def handler; parser.handler end
|
49
|
+
|
50
|
+
# @!endgroup
|
51
|
+
|
52
|
+
# @param [Tag] tag the meta-data tag containing all input to the docstring
|
53
|
+
# @param [DocstringParser] parser the docstring parser object
|
54
|
+
def initialize(tag, parser)
|
55
|
+
self.tag = tag
|
56
|
+
self.parser = parser
|
57
|
+
self.expanded_text = nil
|
58
|
+
end
|
59
|
+
|
60
|
+
# @!group Parser callbacks
|
61
|
+
|
62
|
+
# Called when processing the directive. Subclasses should implement
|
63
|
+
# this method to perform all functionality of the directive.
|
64
|
+
#
|
65
|
+
# @abstract implement this method to perform all data processing for
|
66
|
+
# the directive.
|
67
|
+
# @return [void]
|
68
|
+
def call; raise NotImplementedError end
|
69
|
+
|
70
|
+
# Called after parsing all directives and tags in the docstring. Used
|
71
|
+
# to perform any cleanup after all directives perform their main task.
|
72
|
+
# @return [void]
|
73
|
+
def after_parse; end
|
74
|
+
|
75
|
+
protected :parser
|
76
|
+
end
|
77
|
+
|
78
|
+
# Ends a group listing definition. Group definition automatically end
|
79
|
+
# when class or module blocks are closed, and defining a new group overrides
|
80
|
+
# the last group definition, but occasionally you need to end the current
|
81
|
+
# group to return to the default listing. Use {tag:!group} to begin a
|
82
|
+
# group listing.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# class Controller
|
86
|
+
# # @!group Callbacks
|
87
|
+
#
|
88
|
+
# def before_filter; end
|
89
|
+
# def after_filter; end
|
90
|
+
#
|
91
|
+
# # @!endgroup
|
92
|
+
#
|
93
|
+
# def index; end
|
94
|
+
# end
|
95
|
+
# @see tag:!group
|
96
|
+
# @since 0.6.0
|
97
|
+
class EndGroupDirective < Directive
|
98
|
+
def call
|
99
|
+
return unless handler
|
100
|
+
handler.extra_state.group = nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Defines a group listing. All methods (and attributes) seen after this
|
105
|
+
# directive are placed into a group with the given description as the
|
106
|
+
# group name. The group listing is used by templates to organize methods
|
107
|
+
# and attributes into respective logical groups. To end a group listing
|
108
|
+
# use {tag:!endgroup}.
|
109
|
+
#
|
110
|
+
# @note A group definition only applies to the scope it is defined in.
|
111
|
+
# If a new class or module is opened after the directive, this directive
|
112
|
+
# will not apply to methods in that class or module.
|
113
|
+
# @example
|
114
|
+
# # @!group Callbacks
|
115
|
+
#
|
116
|
+
# def before_filter; end
|
117
|
+
# def after_filter; end
|
118
|
+
# @see tag:!endgroup
|
119
|
+
# @since 0.6.0
|
120
|
+
class GroupDirective < Directive
|
121
|
+
def call
|
122
|
+
return unless handler
|
123
|
+
handler.extra_state.group = tag.text
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Defines a block of text to be expanded whenever the macro is called by name
|
128
|
+
# in subsequent docstrings. The macro data can be any arbitrary text data, be
|
129
|
+
# it regular documentation, meta-data tags or directives.
|
130
|
+
#
|
131
|
+
# == Defining a Macro
|
132
|
+
#
|
133
|
+
# A macro must first be defined in order to be used. Note that a macro is also
|
134
|
+
# expanded upon definition if it defined on an object (the docstring of a
|
135
|
+
# method, class, module or constant object as opposed to a free standing
|
136
|
+
# comment). To define a macro, use the "new" or "attach" identifier in the
|
137
|
+
# types specifier list. A macro will also automatically be created if an
|
138
|
+
# indented macro data block is given, so the keywords are not strictly needed.
|
139
|
+
#
|
140
|
+
# === Anonymous Macros
|
141
|
+
#
|
142
|
+
# In addition to standard named macros, macros can be defined anonymously if
|
143
|
+
# no name is given. In this case, they can not be re-used in future docstrings,
|
144
|
+
# but they will expand in the first definition. This is useful when needing
|
145
|
+
# to take advantage of the macro expansion variables (described below).
|
146
|
+
#
|
147
|
+
# == Using a Macro
|
148
|
+
#
|
149
|
+
# To re-use a macro in another docstring after it is defined, simply use
|
150
|
+
# <tt>@!macro the_name</tt> with no indented block of macro data. The resulting
|
151
|
+
# data will be expanded in place.
|
152
|
+
#
|
153
|
+
# == Attaching a Macro to a DSL Method
|
154
|
+
#
|
155
|
+
# Macros can be defined to auto-expand on DSL-style class method calls. To
|
156
|
+
# define a macro to be auto expanded in this way, use the "attach" keyword
|
157
|
+
# in the type specifier list ("new" is implied).
|
158
|
+
#
|
159
|
+
# Attached macros can also be attached directly on the class method declaration
|
160
|
+
# that provides the DSL method to its subclasses. The syntax in either case
|
161
|
+
# is the same.
|
162
|
+
#
|
163
|
+
# == Macro Expansion Variables
|
164
|
+
#
|
165
|
+
# In the case of using macros on DSL-style method calls, a number of expansion
|
166
|
+
# variables can be used for interpolation inside of the macro data. The variables,
|
167
|
+
# similar in syntax to Ruby's global variables, are as follows:
|
168
|
+
#
|
169
|
+
# * $0 - the method name being called
|
170
|
+
# * $1, $2, $3, ... - the Nth argument in the method call
|
171
|
+
# * $& - the full source line
|
172
|
+
#
|
173
|
+
# The following example shows what the expansion variables might hold for a given
|
174
|
+
# DSL method call:
|
175
|
+
#
|
176
|
+
# property :foo, :a, :b, :c, String
|
177
|
+
# # $0 => "property"
|
178
|
+
# # $1 => "foo"
|
179
|
+
# # $2 => "a"
|
180
|
+
# # $& => "property :foo, :a, :b, :c, String"
|
181
|
+
#
|
182
|
+
# === Ranges
|
183
|
+
#
|
184
|
+
# Ranges are also acceptable with the syntax <tt>${N-M}</tt>. Negative values
|
185
|
+
# on either N or M are valid, and refer to indexes from the end of the list.
|
186
|
+
# Consider a DSL method that creates a method using the first argument with
|
187
|
+
# argument names following, ending with the return type of the method. This
|
188
|
+
# could be documented as:
|
189
|
+
#
|
190
|
+
# # @!macro dsl_method
|
191
|
+
# # @!method $1(${2--2})
|
192
|
+
# # @return [${-1}] the return value of $0
|
193
|
+
# create_method_with_args :foo, :a, :b, :c, String
|
194
|
+
#
|
195
|
+
# As described, the method is using the signature <tt>foo(a, b, c)</tt> and the return
|
196
|
+
# type from the last argument, +String+. When using ranges, tokens are joined
|
197
|
+
# with commas. Note that this includes using $0:
|
198
|
+
#
|
199
|
+
# !!!plain
|
200
|
+
# $0-1 # => Interpolates to "create_method_with_args, foo"
|
201
|
+
#
|
202
|
+
# If you want to separate them with spaces, use <tt>$1 $2 $3 $4 ...</tt>. Note that
|
203
|
+
# if the token cannot be expanded, it will return the empty string (not an error),
|
204
|
+
# so it would be safe to list <tt>$1 $2 ... $10</tt>, for example.
|
205
|
+
#
|
206
|
+
# === Escaping Interpolation
|
207
|
+
#
|
208
|
+
# Interpolation can be escaped by prefixing the +$+ with +\\\+, like so:
|
209
|
+
#
|
210
|
+
# # @!macro foo
|
211
|
+
# # I have \$2.00 USD.
|
212
|
+
#
|
213
|
+
# @example Defining a simple macro
|
214
|
+
# # @!macro [new] returnself
|
215
|
+
# # @return [self] returns itself
|
216
|
+
# @example Using a simple macro in multiple docstrings
|
217
|
+
# # Documentation for map
|
218
|
+
# # ...
|
219
|
+
# # @macro returnself
|
220
|
+
# def map; end
|
221
|
+
#
|
222
|
+
# # Documentation for filter
|
223
|
+
# # ...
|
224
|
+
# # @macro returnself
|
225
|
+
# def filter; end
|
226
|
+
# @example Attaching a macro to a class method (for DSL usage)
|
227
|
+
# class Resource
|
228
|
+
# # Defines a new property
|
229
|
+
# # @param [String] name the property name
|
230
|
+
# # @param [Class] type the property's type
|
231
|
+
# # @!macro [attach] property
|
232
|
+
# # @return [$2] the $1 property
|
233
|
+
# def self.property(name, type) end
|
234
|
+
# end
|
235
|
+
#
|
236
|
+
# class Post < Resource
|
237
|
+
# property :title, String
|
238
|
+
# property :view_count, Integer
|
239
|
+
# end
|
240
|
+
# @example Attaching a macro directly to a DSL method
|
241
|
+
# class Post < Resource
|
242
|
+
# # @!macro [attach] property
|
243
|
+
# # @return [$2] the $1 property
|
244
|
+
# property :title, String
|
245
|
+
#
|
246
|
+
# # Macro will expand on this definition too
|
247
|
+
# property :view_count, Integer
|
248
|
+
# end
|
249
|
+
# @since 0.7.0
|
250
|
+
class MacroDirective < Directive
|
251
|
+
def call
|
252
|
+
raise TagFormatError if tag.name.nil? && tag.text.to_s.empty?
|
253
|
+
unless macro_data = find_or_create
|
254
|
+
warn
|
255
|
+
return
|
256
|
+
end
|
257
|
+
|
258
|
+
self.expanded_text = expand(macro_data)
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
|
263
|
+
def new?
|
264
|
+
(tag.types && tag.types.include?('new')) ||
|
265
|
+
(tag.text && !tag.text.strip.empty?)
|
266
|
+
end
|
267
|
+
|
268
|
+
def attach?
|
269
|
+
new? && # must have data or there is nothing to attach
|
270
|
+
class_method? || # always attach to class methods
|
271
|
+
(tag.types && tag.types.include?('attach'))
|
272
|
+
end
|
273
|
+
|
274
|
+
def class_method?
|
275
|
+
object && object.is_a?(CodeObjects::MethodObject) &&
|
276
|
+
object.scope == :class
|
277
|
+
end
|
278
|
+
|
279
|
+
def anonymous?
|
280
|
+
tag.name.nil? || tag.name.empty?
|
281
|
+
end
|
282
|
+
|
283
|
+
def expand(macro_data)
|
284
|
+
return if attach? && class_method?
|
285
|
+
return if !anonymous? && new? &&
|
286
|
+
(!handler || handler.statement.source.empty?)
|
287
|
+
call_params = []
|
288
|
+
caller_method = nil
|
289
|
+
full_source = ''
|
290
|
+
if handler
|
291
|
+
call_params = handler.call_params
|
292
|
+
caller_method = handler.caller_method
|
293
|
+
full_source = handler.statement.source
|
294
|
+
end
|
295
|
+
all_params = ([caller_method] + call_params).compact
|
296
|
+
CodeObjects::MacroObject.expand(macro_data, all_params, full_source)
|
297
|
+
end
|
298
|
+
|
299
|
+
def find_or_create
|
300
|
+
if new? || attach?
|
301
|
+
if handler && attach?
|
302
|
+
obj = object ? object :
|
303
|
+
P("#{handler.namespace}.#{handler.caller_method}")
|
304
|
+
else
|
305
|
+
obj = nil
|
306
|
+
end
|
307
|
+
if anonymous? # anonymous macro
|
308
|
+
return tag.text || ""
|
309
|
+
else
|
310
|
+
macro = CodeObjects::MacroObject.create(tag.name, tag.text, obj)
|
311
|
+
end
|
312
|
+
else
|
313
|
+
macro = CodeObjects::MacroObject.find(tag.name)
|
314
|
+
end
|
315
|
+
|
316
|
+
macro ? macro.macro_data : nil
|
317
|
+
end
|
318
|
+
|
319
|
+
def warn
|
320
|
+
if object && handler
|
321
|
+
log.warn "Invalid/missing macro name for " +
|
322
|
+
"#{object.path} (#{handler.parser.file}:#{handler.statement.line})"
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
# Defines a method object with a given method signature, using indented
|
328
|
+
# block data as the method's docstring. The signature is similar to the
|
329
|
+
# {tag:overload} tag. The comment containing this directive does not need
|
330
|
+
# to be attached to any source, but if it is, that source code will be
|
331
|
+
# used as the method's source.
|
332
|
+
#
|
333
|
+
# To define an attribute method, see {tag:!attribute}
|
334
|
+
#
|
335
|
+
# @note For backwards compatibility support, you do not need to indent
|
336
|
+
# the method's docstring text. If a +@!method+ directive is seen with
|
337
|
+
# no indented block, the entire docstring is used as the new method's
|
338
|
+
# docstring text.
|
339
|
+
# @example Defining a simple method
|
340
|
+
# # @!method quit(username, message = "Quit")
|
341
|
+
# # Sends a quit message to the server for a +username+.
|
342
|
+
# # @param [String] username the username to quit
|
343
|
+
# # @param [String] message the quit message
|
344
|
+
# quit_message_method
|
345
|
+
# @example Attaching multiple methods to the same source
|
346
|
+
# # @!method method1
|
347
|
+
# # @!method method2
|
348
|
+
# create_methods :method1, :method2
|
349
|
+
# @see tag:!attribute
|
350
|
+
# @since 0.7.0
|
351
|
+
class MethodDirective < Directive
|
352
|
+
SCOPE_MATCH = /\A\s*self\s*\.\s*/
|
353
|
+
|
354
|
+
def call; end
|
355
|
+
|
356
|
+
def after_parse
|
357
|
+
return unless handler
|
358
|
+
use_indented_text
|
359
|
+
create_object
|
360
|
+
end
|
361
|
+
|
362
|
+
protected
|
363
|
+
|
364
|
+
def method_name
|
365
|
+
sig = sanitized_tag_signature
|
366
|
+
if sig && sig =~ /^#{CodeObjects::METHODNAMEMATCH}(\s|\(|$)/
|
367
|
+
sig[/\A\s*([^\(; \t]+)/, 1]
|
368
|
+
else
|
369
|
+
handler.call_params.first
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
def method_signature
|
374
|
+
"def #{sanitized_tag_signature || method_name}"
|
375
|
+
end
|
376
|
+
|
377
|
+
def sanitized_tag_signature
|
378
|
+
if tag.name && tag.name =~ SCOPE_MATCH
|
379
|
+
parser.state.scope = :class
|
380
|
+
$'
|
381
|
+
else
|
382
|
+
tag.name
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
def use_indented_text
|
387
|
+
return if tag.text.empty?
|
388
|
+
handler = parser.handler
|
389
|
+
object = parser.object
|
390
|
+
self.parser = parser.class.new(parser.library)
|
391
|
+
parser.parse(tag.text, object, handler)
|
392
|
+
end
|
393
|
+
|
394
|
+
def create_object
|
395
|
+
name = method_name
|
396
|
+
scope = parser.state.scope || handler.scope
|
397
|
+
visibility = parser.state.visibility || handler.visibility
|
398
|
+
ns = CodeObjects::NamespaceObject === object ? object : handler.namespace
|
399
|
+
obj = CodeObjects::MethodObject.new(ns, name, scope)
|
400
|
+
handler.register_file_info(obj)
|
401
|
+
handler.register_source(obj)
|
402
|
+
handler.register_visibility(obj, visibility)
|
403
|
+
handler.register_group(obj)
|
404
|
+
obj.signature = method_signature
|
405
|
+
obj.parameters = OverloadTag.new(:overload, method_signature).parameters
|
406
|
+
obj.docstring = Docstring.new!(parser.text, parser.tags, obj,
|
407
|
+
parser.raw_text, parser.reference)
|
408
|
+
handler.register_module_function(obj)
|
409
|
+
obj
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
# Defines an attribute with a given name, using indented block data as the
|
414
|
+
# attribute's docstring. If the type specifier is supplied with "r", "w", or
|
415
|
+
# "rw", the attribute is made readonly, writeonly or readwrite respectively.
|
416
|
+
# A readwrite attribute is the default, if no type is specified. The comment
|
417
|
+
# containing this directive does not need to be attached to any source, but
|
418
|
+
# if it is, that source code will be used as the method's source.
|
419
|
+
#
|
420
|
+
# To define an regular method, see {tag:!method}
|
421
|
+
#
|
422
|
+
# @note For backwards compatibility support, you do not need to indent
|
423
|
+
# the attribute's docstring text. If an +@!attribute+ directive is seen with
|
424
|
+
# no indented block, the entire docstring is used as the new attribute's
|
425
|
+
# docstring text.
|
426
|
+
# @example Defining a simple readonly attribute
|
427
|
+
# # @!attribute [r] count
|
428
|
+
# # @return [Fixnum] the size of the list
|
429
|
+
# @example Defining a simple readwrite attribute
|
430
|
+
# # @!attribute name
|
431
|
+
# # @return [String] the name of the user
|
432
|
+
# @see tag:!method
|
433
|
+
# @since 0.7.0
|
434
|
+
class AttributeDirective < MethodDirective
|
435
|
+
def after_parse
|
436
|
+
return unless handler
|
437
|
+
use_indented_text
|
438
|
+
create_attribute_data(create_object)
|
439
|
+
end
|
440
|
+
|
441
|
+
protected
|
442
|
+
|
443
|
+
def method_name
|
444
|
+
name = sanitized_tag_signature || handler.call_params.first
|
445
|
+
name += '=' unless readable?
|
446
|
+
name
|
447
|
+
end
|
448
|
+
|
449
|
+
def method_signature
|
450
|
+
if readable?
|
451
|
+
"def #{method_name}"
|
452
|
+
else
|
453
|
+
"def #{method_name}(value)"
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
private
|
458
|
+
|
459
|
+
def create_attribute_data(object)
|
460
|
+
return unless object
|
461
|
+
clean_name = object.name.to_s.sub(/=$/, '')
|
462
|
+
attrs = object.namespace.attributes[object.scope]
|
463
|
+
attrs[clean_name] ||= SymbolHash[:read => nil, :write => nil]
|
464
|
+
if readable?
|
465
|
+
attrs[clean_name][:read] = object
|
466
|
+
end
|
467
|
+
if writable?
|
468
|
+
if object.name.to_s[-1,1] == '='
|
469
|
+
writer = object
|
470
|
+
writer.parameters = [['value', nil]]
|
471
|
+
else
|
472
|
+
writer = CodeObjects::MethodObject.new(object.namespace,
|
473
|
+
object.name.to_s + '=', object.scope)
|
474
|
+
writer.signature = "def #{object.name}=(value)"
|
475
|
+
writer.visibility = object.visibility
|
476
|
+
writer.dynamic = object.dynamic
|
477
|
+
writer.source = object.source
|
478
|
+
writer.group = object.group
|
479
|
+
writer.parameters = [['value', nil]]
|
480
|
+
handler.register_file_info(writer)
|
481
|
+
end
|
482
|
+
attrs[clean_name][:write] = writer
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
def writable?
|
487
|
+
!tag.types || tag.types.join.include?('w')
|
488
|
+
end
|
489
|
+
|
490
|
+
def readable?
|
491
|
+
!tag.types || tag.types.join =~ /(?!w)r/
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
# Parses a block of code as if it were present in the source file at that
|
496
|
+
# location. This directive is useful if a class has dynamic meta-programmed
|
497
|
+
# behaviour that cannot be recognized by YARD.
|
498
|
+
#
|
499
|
+
# You can specify the language of the code block using the types
|
500
|
+
# specification list. By default, the code language is "ruby".
|
501
|
+
#
|
502
|
+
# @example Documenting dynamic module inclusion
|
503
|
+
# class User
|
504
|
+
# # includes "UserMixin" and extends "UserMixin::ClassMethods"
|
505
|
+
# # using the UserMixin.included callback.
|
506
|
+
# # @!parse include UserMixin
|
507
|
+
# # @!parse extend UserMixin::ClassMethods
|
508
|
+
# end
|
509
|
+
# @example Declaring a method as an attribute
|
510
|
+
# # This should really be an attribute
|
511
|
+
# # @!parse attr_reader :foo
|
512
|
+
# def object; @parent.object end
|
513
|
+
# @example Parsing C code
|
514
|
+
# # @!parse [c]
|
515
|
+
# # void Init_Foo() {
|
516
|
+
# # rb_define_method(rb_cFoo, "method", method, 0);
|
517
|
+
# # }
|
518
|
+
# @since 0.8.0
|
519
|
+
class ParseDirective < Directive
|
520
|
+
def call
|
521
|
+
lang = tag.types ? tag.types.first.to_sym :
|
522
|
+
(handler ? handler.parser.parser_type : :ruby)
|
523
|
+
if handler && lang == handler.parser.parser_type
|
524
|
+
pclass = Parser::SourceParser.parser_types[handler.parser.parser_type]
|
525
|
+
pobj = pclass.new(tag.text, handler.parser.file)
|
526
|
+
pobj.parse
|
527
|
+
handler.parser.process(pobj.enumerator)
|
528
|
+
else # initialize a new parse chain
|
529
|
+
src_parser = Parser::SourceParser.new(lang, handler ? handler.globals : nil)
|
530
|
+
src_parser.file = handler.parser.file if handler
|
531
|
+
src_parser.parse(StringIO.new(tag.text))
|
532
|
+
end
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
# Modifies the current parsing scope (class or instance). If this
|
537
|
+
# directive is defined on a docstring attached to an object definition,
|
538
|
+
# it is applied only to that object. Otherwise, it applies the scope
|
539
|
+
# to all future objects in the namespace.
|
540
|
+
#
|
541
|
+
# @example Modifying the scope of a DSL method
|
542
|
+
# # @!scope class
|
543
|
+
# cattr_accessor :subclasses
|
544
|
+
# @example Modifying the scope of a set of methods
|
545
|
+
# # @!scope class
|
546
|
+
#
|
547
|
+
# # Documentation for method1
|
548
|
+
# def method1; end
|
549
|
+
#
|
550
|
+
# # Documentation for method2
|
551
|
+
# def method2; end
|
552
|
+
# @since 0.7.0
|
553
|
+
class ScopeDirective < Directive
|
554
|
+
def call
|
555
|
+
if %w(class instance module).include?(tag.text)
|
556
|
+
if object.is_a?(CodeObjects::MethodObject)
|
557
|
+
object.scope = tag.text.to_sym
|
558
|
+
else
|
559
|
+
parser.state.scope = tag.text.to_sym
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
# Modifies the current parsing visibility (public, protected, or private).
|
566
|
+
# If this directive is defined on a docstring attached to an object
|
567
|
+
# definition, it is applied only to that object. Otherwise, it applies
|
568
|
+
# the visibility to all future objects in the namespace.
|
569
|
+
#
|
570
|
+
# @example Modifying the visibility of a DSL method
|
571
|
+
# # @!visibility private
|
572
|
+
# cattr_accessor :subclasses
|
573
|
+
# @example Modifying the visibility of a set of methods
|
574
|
+
# # Note that Ruby's "protected" is recommended over this directive
|
575
|
+
# # @!visibility protected
|
576
|
+
#
|
577
|
+
# # Documentation for method1
|
578
|
+
# def method1; end
|
579
|
+
#
|
580
|
+
# # Documentation for method2
|
581
|
+
# def method2; end
|
582
|
+
# @since 0.7.0
|
583
|
+
class VisibilityDirective < Directive
|
584
|
+
def call
|
585
|
+
if %w(public protected private).include?(tag.text)
|
586
|
+
if object.is_a?(CodeObjects::Base)
|
587
|
+
object.visibility = tag.text.to_sym
|
588
|
+
else
|
589
|
+
parser.state.visibility = tag.text.to_sym
|
590
|
+
end
|
591
|
+
end
|
592
|
+
end
|
593
|
+
end
|
594
|
+
end
|
595
|
+
end
|