### Home Classes Methods

### In Files

- lib/yard/handlers/ruby/struct_handler_methods.rb

### Methods

- #add_reader_tags
- #add_writer_tags
- #create_attributes
- #create_class
- #create_member_method?
- #create_reader
- #create_writer
- #member_tag_for_member
- #members_from_tags
- #return_type_from_tag

### Included Modules

- YARD::CodeObjects

### Files

- LICENSE.txt
- MIT.txt

### Class/Module Index

Quicksearch

- YARD
- YARD::CLI
- YARD::CLI::Command
- YARD::CLI::CommandParser
- YARD::CLI::Config
- YARD::CLI::Diff
- YARD::CLI::Display
- YARD::CLI::Gems
- YARD::CLI::Graph
- YARD::CLI::GraphOptions
- YARD::CLI::Help
- YARD::CLI::I18n
- YARD::CLI::List
- YARD::CLI::MarkupTypes
- YARD::CLI::Server
- YARD::CLI::Stats
- YARD::CLI::YRI
- YARD::CLI::Yardoc
- YARD::CLI::YardocOptions
- YARD::CLI::YardoptsCommand
- YARD::CodeObjects
- YARD::CodeObjects::Base
- YARD::CodeObjects::ClassObject
- YARD::CodeObjects::ClassVariableObject
- YARD::CodeObjects::CodeObjectList
- YARD::CodeObjects::ConstantObject
- YARD::CodeObjects::ExtendedMethodObject
- YARD::CodeObjects::ExtraFileObject
- YARD::CodeObjects::MacroObject
- YARD::CodeObjects::MethodObject
- YARD::CodeObjects::ModuleObject
- YARD::CodeObjects::NamespaceObject
- YARD::CodeObjects::Proxy
- YARD::CodeObjects::ProxyMethodError
- YARD::CodeObjects::RootObject
- YARD::Config
- YARD::Docstring
- YARD::DocstringParser
- YARD::Handlers
- YARD::Handlers::Base
- YARD::Handlers::C
- YARD::Handlers::C::AliasHandler
- YARD::Handlers::C::AttributeHandler
- YARD::Handlers::C::Base
- YARD::Handlers::C::ClassHandler
- YARD::Handlers::C::ConstantHandler
- YARD::Handlers::C::HandlerMethods
- YARD::Handlers::C::InitHandler
- YARD::Handlers::C::MethodHandler
- YARD::Handlers::C::MixinHandler
- YARD::Handlers::C::ModuleHandler
- YARD::Handlers::C::OverrideCommentHandler
- YARD::Handlers::C::PathHandler
- YARD::Handlers::C::StructHandler
- YARD::Handlers::C::SymbolHandler
- YARD::Handlers::HandlerAborted
- YARD::Handlers::NamespaceMissingError
- YARD::Handlers::Processor
- YARD::Handlers::Ruby
- YARD::Handlers::Ruby::AliasHandler
- YARD::Handlers::Ruby::AttributeHandler
- YARD::Handlers::Ruby::Base
- YARD::Handlers::Ruby::ClassConditionHandler
- YARD::Handlers::Ruby::ClassHandler
- YARD::Handlers::Ruby::ClassVariableHandler
- YARD::Handlers::Ruby::CommentHandler
- YARD::Handlers::Ruby::ConstantHandler
- YARD::Handlers::Ruby::DSLHandler
- YARD::Handlers::Ruby::DSLHandlerMethods
- YARD::Handlers::Ruby::ExceptionHandler
- YARD::Handlers::Ruby::ExtendHandler
- YARD::Handlers::Ruby::HandlesExtension
- YARD::Handlers::Ruby::Legacy
- YARD::Handlers::Ruby::Legacy::AliasHandler
- YARD::Handlers::Ruby::Legacy::AttributeHandler
- YARD::Handlers::Ruby::Legacy::Base
- YARD::Handlers::Ruby::Legacy::ClassConditionHandler
- YARD::Handlers::Ruby::Legacy::ClassHandler
- YARD::Handlers::Ruby::Legacy::ClassVariableHandler
- YARD::Handlers::Ruby::Legacy::CommentHandler
- YARD::Handlers::Ruby::Legacy::ConstantHandler
- YARD::Handlers::Ruby::Legacy::DSLHandler
- YARD::Handlers::Ruby::Legacy::ExceptionHandler
- YARD::Handlers::Ruby::Legacy::ExtendHandler
- YARD::Handlers::Ruby::Legacy::MethodHandler
- YARD::Handlers::Ruby::Legacy::MixinHandler
- YARD::Handlers::Ruby::Legacy::ModuleFunctionHandler
- YARD::Handlers::Ruby::Legacy::ModuleHandler
- YARD::Handlers::Ruby::Legacy::PrivateConstantHandler
- YARD::Handlers::Ruby::Legacy::VisibilityHandler
- YARD::Handlers::Ruby::Legacy::YieldHandler
- YARD::Handlers::Ruby::MethodCallWrapper
- YARD::Handlers::Ruby::MethodConditionHandler
- YARD::Handlers::Ruby::MethodHandler
- YARD::Handlers::Ruby::MixinHandler
- YARD::Handlers::Ruby::ModuleFunctionHandler
- YARD::Handlers::Ruby::ModuleHandler
- YARD::Handlers::Ruby::PrivateConstantHandler
- YARD::Handlers::Ruby::StructHandlerMethods
- YARD::Handlers::Ruby::TestNodeWrapper
- YARD::Handlers::Ruby::VisibilityHandler
- YARD::Handlers::Ruby::YieldHandler
- YARD::I18n
- YARD::I18n::Locale
- YARD::I18n::Message
- YARD::I18n::Messages
- YARD::I18n::PotGenerator
- YARD::I18n::Text
- YARD::Logger
- YARD::Options
- YARD::Parser
- YARD::Parser::Base
- YARD::Parser::C
- YARD::Parser::C::BodyStatement
- YARD::Parser::C::CParser
- YARD::Parser::C::Comment
- YARD::Parser::C::CommentParser
- YARD::Parser::C::Statement
- YARD::Parser::C::ToplevelStatement
- YARD::Parser::OrderedParser
- YARD::Parser::ParserSyntaxError
- YARD::Parser::Ruby
- YARD::Parser::Ruby::AstNode
- YARD::Parser::Ruby::ClassNode
- YARD::Parser::Ruby::CommentNode
- YARD::Parser::Ruby::ConditionalNode
- YARD::Parser::Ruby::KeywordNode
- YARD::Parser::Ruby::Legacy
- YARD::Parser::Ruby::Legacy::RubyLex
- YARD::Parser::Ruby::Legacy::RubyLex::BufferedReader
- YARD::Parser::Ruby::Legacy::RubyParser
- YARD::Parser::Ruby::Legacy::RubyToken
- YARD::Parser::Ruby::Legacy::RubyToken::TkBlockContents
- YARD::Parser::Ruby::Legacy::RubyToken::TkError
- YARD::Parser::Ruby::Legacy::RubyToken::TkId
- YARD::Parser::Ruby::Legacy::RubyToken::TkKW
- YARD::Parser::Ruby::Legacy::RubyToken::TkNode
- YARD::Parser::Ruby::Legacy::RubyToken::TkOPASGN
- YARD::Parser::Ruby::Legacy::RubyToken::TkOp
- YARD::Parser::Ruby::Legacy::RubyToken::TkStatementEnd
- YARD::Parser::Ruby::Legacy::RubyToken::TkUnknownChar
- YARD::Parser::Ruby::Legacy::RubyToken::TkVal
- YARD::Parser::Ruby::Legacy::RubyToken::TkWhitespace
- YARD::Parser::Ruby::Legacy::RubyToken::Token
- YARD::Parser::Ruby::Legacy::Statement
- YARD::Parser::Ruby::Legacy::StatementList
- YARD::Parser::Ruby::Legacy::TokenList
- YARD::Parser::Ruby::LiteralNode
- YARD::Parser::Ruby::LoopNode
- YARD::Parser::Ruby::MethodCallNode
- YARD::Parser::Ruby::MethodDefinitionNode
- YARD::Parser::Ruby::ModuleNode
- YARD::Parser::Ruby::ParameterNode
- YARD::Parser::Ruby::ReferenceNode
- YARD::Parser::Ruby::RipperParser
- YARD::Parser::Ruby::RubyParser
- YARD::Parser::SourceParser
- YARD::Parser::UndocumentableError
- YARD::Rake
- YARD::Rake::YardocTask
- YARD::Registry
- YARD::RegistryStore
- YARD::Serializers
- YARD::Serializers::Base
- YARD::Serializers::FileSystemSerializer
- YARD::Serializers::ProcessSerializer
- YARD::Serializers::StdoutSerializer
- YARD::Serializers::YardocSerializer
- YARD::Server
- YARD::Server::Adapter
- YARD::Server::Commands
- YARD::Server::Commands::Base
- YARD::Server::Commands::DisplayFileCommand
- YARD::Server::Commands::DisplayObjectCommand
- YARD::Server::Commands::FramesCommand
- YARD::Server::Commands::LibraryCommand
- YARD::Server::Commands::LibraryIndexCommand
- YARD::Server::Commands::LibraryOptions
- YARD::Server::Commands::ListCommand
- YARD::Server::Commands::SearchCommand
- YARD::Server::Commands::StaticFileCommand
- YARD::Server::DocServerHelper
- YARD::Server::DocServerSerializer
- YARD::Server::FinishRequest
- YARD::Server::LibraryNotPreparedError
- YARD::Server::LibraryVersion
- YARD::Server::NotFoundError
- YARD::Server::RackAdapter
- YARD::Server::RackMiddleware
- YARD::Server::Router
- YARD::Server::StaticCaching
- YARD::Server::WebrickAdapter
- YARD::Server::WebrickServlet
- YARD::StubProxy
- YARD::Tags
- YARD::Tags::AttributeDirective
- YARD::Tags::DefaultFactory
- YARD::Tags::DefaultTag
- YARD::Tags::Directive
- YARD::Tags::EndGroupDirective
- YARD::Tags::GroupDirective
- YARD::Tags::Library
- YARD::Tags::MacroDirective
- YARD::Tags::MethodDirective
- YARD::Tags::OptionTag
- YARD::Tags::OverloadTag
- YARD::Tags::ParseDirective
- YARD::Tags::RefTag
- YARD::Tags::RefTagList
- YARD::Tags::ScopeDirective
- YARD::Tags::Tag
- YARD::Tags::TagFormatError
- YARD::Tags::VisibilityDirective
- YARD::Templates
- YARD::Templates::Engine
- YARD::Templates::ErbCache
- YARD::Templates::Helpers
- YARD::Templates::Helpers::BaseHelper
- YARD::Templates::Helpers::FilterHelper
- YARD::Templates::Helpers::HtmlHelper
- YARD::Templates::Helpers::HtmlSyntaxHighlightHelper
- YARD::Templates::Helpers::Markup
- YARD::Templates::Helpers::Markup::RDocMarkdown
- YARD::Templates::Helpers::Markup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkupToHtml
- YARD::Templates::Helpers::MarkupHelper
- YARD::Templates::Helpers::MethodHelper
- YARD::Templates::Helpers::ModuleHelper
- YARD::Templates::Helpers::TextHelper
- YARD::Templates::Helpers::UMLHelper
- YARD::Templates::Section
- YARD::Templates::Template
- YARD::Templates::Template::ClassMethods
- YARD::Templates::TemplateOptions
- YARD::Verifier
- Gem
- Gem::DocManager
- Gem::SourceIndex
- Gem::Specification
- Rack
- Rack::Request
- WEBrick
- WEBrick::HTTPRequest
- Array
- File
- Hash
- Insertion
- Module
- Object
- String
- SymbolHash

No matching classes.

# YARD::Handlers::Ruby::StructHandlerMethods

Helper methods to parse @attr_* tags on a class.

@deprecated The use of +@attr+ tags are deprecated since 0.8.0 in favour of

    the +@!attribute+ directive. This module should not be relied on.

@since 0.5.6

### Public Instance Methods

add_reader_tags(klass, new_method, member) click to toggle source

Creates the auto-generated docstring for the getter method of a struct's member. This is used so the generated documentation will look just like that of an attribute defined using attr_accessor.

@param [ClassObject] klass the class whose members we're working with @param [String] member the name of the member we're generating documentation for @return [String] a docstring to be attached to the getter method for this member

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 61
    def add_reader_tags(klass, new_method, member)
      member_tag = member_tag_for_member(klass, member, :read)
      return_type = return_type_from_tag(member_tag)
      getter_doc_text = member_tag ? member_tag.text : "Returns the value of attribute #{member}"
      new_method.docstring.replace(getter_doc_text)
      new_method.add_tag YARD::Tags::Tag.new(:return, "the current value of #{member}", return_type)
    end

add_writer_tags(klass, new_method, member) click to toggle source

Creates the auto-generated docstring for the setter method of a struct's member. This is used so the generated documentation will look just like that of an attribute defined using attr_accessor.

@param [ClassObject] klass the class whose members we're working with @param [String] member the name of the member we're generating documentation for @return [String] a docstring to be attached to the setter method for this member

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 76
    def add_writer_tags(klass, new_method, member)
      member_tag = member_tag_for_member(klass, member, :write)
      return_type = return_type_from_tag(member_tag)
      setter_doc_text = member_tag ? member_tag.text : "Sets the attribute #{member}"
      new_method.docstring.replace(setter_doc_text)
      new_method.add_tag YARD::Tags::Tag.new(:param, "the value to set the attribute #{member} to.", return_type, "value")
      new_method.add_tag YARD::Tags::Tag.new(:return, "the newly set value", return_type)
    end

create_attributes(klass, members) click to toggle source

Creates the given member methods and attaches them to the given ClassObject.

@param [ClassObject] klass the class to generate attributes for @param [Array<String>] members a list of member names

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 133
    def create_attributes(klass, members)
      # For each parameter, add reader and writers
      members.each do |member|
        klass.attributes[:instance][member] = SymbolHash[:read => nil, :write => nil]
        create_writer klass, member if create_member_method?(klass, member, :write)
        create_reader klass, member if create_member_method?(klass, member, :read)
      end
    end

create_class(classname, superclass) click to toggle source

Creates and registers a class object with the given name and superclass name. Returns it for further use.

@param [String] classname the name of the class @param [String] superclass the name of the superclass @return [ClassObject] the class object for further processing/method attaching

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 91
    def create_class(classname, superclass)
      register ClassObject.new(namespace, classname) do |o|
        o.superclass = superclass if superclass
        o.superclass.type = :class if o.superclass.is_a?(Proxy)
      end
    end

create_member_method?(klass, member, type = :read) click to toggle source

Determines whether to create an attribute method based on the class's tags.

@param [ClassObject] klass the class whose tags we're searching @param [String] member the name of the struct member we need @param [Symbol] type (:read) reader method, or writer method? @return [Boolean] should the attribute be created?

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 37
    def create_member_method?(klass, member, type = :read)
      return true if (klass.tags(:attr) + klass.tags(:attr_reader) + klass.tags(:attr_writer)).empty?
      return true if member_tag_for_member(klass, member, type)
      return !member_tag_for_member(klass, member, :write) if type == :read
      return !member_tag_for_member(klass, member, :read)
    end

create_reader(klass, member) click to toggle source

Creates the getter (reader) method and attaches it to the class as an attribute. Also sets up the docstring to prettify the documentation output.

@param [ClassObject] klass the class to attach the method to @param [String] member the name of the member we're generating a method for

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 120
    def create_reader(klass, member)
      new_meth = register MethodObject.new(klass, member, :instance) do |o|
        o.signature ||= "def #{member}"
        o.source ||= "#{o.signature}\n  @#{member}\nend"
      end
      add_reader_tags(klass, new_meth, member)
      klass.attributes[:instance][member][:read] = new_meth
    end

create_writer(klass, member) click to toggle source

Creates the setter (writer) method and attaches it to the class as an attribute. Also sets up the docstring to prettify the documentation output.

@param [ClassObject] klass the class to attach the method to @param [String] member the name of the member we're generating a method for

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 103
    def create_writer(klass, member)
      # We want to convert these members into attributes just like
      # as if they were declared using attr_accessor.
      new_meth = register MethodObject.new(klass, "#{member}=", :instance) do |o|
        o.parameters = [['value', nil]]
        o.signature ||= "def #{member}=(value)"
        o.source ||= "#{o.signature}\n  @#{member} = value\nend"
      end
      add_writer_tags(klass, new_meth, member)
      klass.attributes[:instance][member][:write] = new_meth
    end

member_tag_for_member(klass, member, type = :read) click to toggle source

Extracts the user's defined @member tag for a given class and its member. Returns nil if the user did not define a @member tag for this struct entry.

@param [ClassObject] klass the class whose tags we're searching @param [String] member the name of the struct member we need @param [Symbol] type reader method, or writer method? @return [Tags::Tag, nil] the tag matching the request, or nil if not found

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 16
    def member_tag_for_member(klass, member, type = :read)
      specific_tag = type == :read ? :attr_reader : :attr_writer
      (klass.tags(specific_tag) + klass.tags(:attr)).find {|tag| tag.name == member}
    end

members_from_tags(klass) click to toggle source

Retrieves all members defined in @attr* tags

@param [ClassObject] klass the class with the attributes @return [Array<String>] the list of members defined as attributes on the class

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 25
    def members_from_tags(klass)
      tags = klass.tags(:attr) + klass.tags(:attr_reader) + klass.tags(:attr_writer)
      tags.map {|t| t.name }.uniq
    end

return_type_from_tag(member_tag) click to toggle source

Gets the return type for the member in a nicely formatted string. Used to be injected into auto-generated docstrings.

@param [Tags::Tag] member_tag the tag object to check for types @return [String] the user-declared type of the struct member, or [Object] if

    the user did not define a type for this member.

    # File lib/yard/handlers/ruby/struct_handler_methods.rb, line 50
    def return_type_from_tag(member_tag)
      (member_tag && member_tag.types) ? member_tag.types : "Object"
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.