Class: YARD::Handlers::Ruby::Legacy::AttributeHandler
- Inherits:
-
Base
- Object
- YARD::Handlers::Base
- Base
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- Defined in:
- lib/yard/handlers/ruby/legacy/attribute_handler.rb
Constant Summary
Constants included from YARD::Parser::Ruby::Legacy::RubyToken
EXPR_ARG, EXPR_BEG, EXPR_CLASS, EXPR_DOT, EXPR_END, EXPR_FNAME, EXPR_MID, NEWLINE_TOKEN, TkReading2Token, TkSymbol2Token, TokenDefinitions
Constants included from YARD::CodeObjects
BUILTIN_ALL, BUILTIN_CLASSES, BUILTIN_EXCEPTIONS, BUILTIN_EXCEPTIONS_HASH, BUILTIN_MODULES, CONSTANTMATCH, CSEP, CSEPQ, ISEP, ISEPQ, METHODMATCH, METHODNAMEMATCH, NAMESPACEMATCH, NSEP, NSEPQ
Instance Method Summary
Methods inherited from Base
Methods included from YARD::Parser::Ruby::Legacy::RubyToken
#Token, def_token, #set_token_position
Methods inherited from YARD::Handlers::Base
clear_subclasses, #ensure_loaded!, handlers, handles, handles?, #initialize, namespace_only, namespace_only?, #parse_block, #push_state, #register, subclasses
Constructor Details
This class inherits a constructor from YARD::Handlers::Base
Instance Method Details
- (Object) process
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/yard/handlers/ruby/legacy/attribute_handler.rb', line 4 def process begin attr_type = statement.tokens.first.text.to_sym symbols = tokval_list statement.tokens[2..-1], :attr, TkTRUE, TkFALSE read, write = true, false rescue SyntaxError raise YARD::Parser::UndocumentableError, attr_type end # Change read/write based on attr_reader/writer/accessor case attr_type when :attr # In the case of 'attr', the second parameter (if given) isn't a symbol. write = symbols.pop if symbols.size == 2 when :attr_accessor write = true when :attr_reader # change nothing when :attr_writer read, write = false, true end # Add all attributes symbols.each do |name| namespace.attributes[scope][name] = SymbolHash[:read => nil, :write => nil] # Show their methods as well {:read => name, :write => "#{name}="}.each do |type, meth| if (type == :read ? read : write) namespace.attributes[scope][name][type] = MethodObject.new(namespace, meth, scope) do |o| if type == :write o.parameters = [['value', nil]] src = "def #{meth}(value)" full_src = "#{src}\n @#{name} = value\nend" doc = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to." else src = "def #{meth}" full_src = "#{src}\n @#{name}\nend" doc = "Returns the value of attribute #{name}" end o.source ||= full_src o.signature ||= src o.docstring = statement.comments.to_s.empty? ? doc : statement.comments end # Register the objects explicitly register namespace.attributes[scope][name][type] elsif obj = namespace.children.find {|o| o.name == meth.to_sym && o.scope == scope } # register an existing method as attribute namespace.attributes[scope][name][type] = obj end end end end |