Class: Rubyzen::Declarations::AttributeDeclaration
- Inherits:
-
Object
- Object
- Rubyzen::Declarations::AttributeDeclaration
- Includes:
- Providers::ClassNameProvider, Providers::FilePathProvider, Providers::LineNumberProvider, Providers::VisibilityProvider
- Defined in:
- lib/rubyzen/declarations/attribute_declaration.rb
Overview
Represents an attr_reader, attr_writer, or attr_accessor declaration.
Instance Attribute Summary collapse
- #node ⇒ RuboCop::AST::Node readonly
- #parent_class ⇒ ClassDeclaration, ModuleDeclaration (also: #parent) readonly
Instance Method Summary collapse
-
#accessor? ⇒ Boolean
True only for
attr_accessor. -
#initialize(node, parent_class) ⇒ AttributeDeclaration
constructor
A new instance of AttributeDeclaration.
-
#name ⇒ String
Returns the attribute type name.
-
#reader? ⇒ Boolean
True for
attr_readerandattr_accessor. -
#symbols ⇒ Array<String>
Returns the declared symbol names.
-
#writer? ⇒ Boolean
True for
attr_writerandattr_accessor.
Methods included from Providers::VisibilityProvider
#private?, #protected?, #public?, #visibility
Methods included from Providers::LineNumberProvider
Methods included from Providers::ClassNameProvider
Methods included from Providers::FilePathProvider
Constructor Details
#initialize(node, parent_class) ⇒ AttributeDeclaration
Returns a new instance of AttributeDeclaration.
27 28 29 30 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 27 def initialize(node, parent_class) @node = node @parent_class = parent_class end |
Instance Attribute Details
#node ⇒ RuboCop::AST::Node (readonly)
19 20 21 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 19 def node @node end |
#parent_class ⇒ ClassDeclaration, ModuleDeclaration (readonly) Also known as: parent
22 23 24 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 22 def parent_class @parent_class end |
Instance Method Details
#accessor? ⇒ Boolean
Returns true only for attr_accessor.
57 58 59 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 57 def accessor? name == 'attr_accessor' end |
#name ⇒ String
Returns the attribute type name.
35 36 37 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 35 def name node.method_name.to_s end |
#reader? ⇒ Boolean
Returns true for attr_reader and attr_accessor.
47 48 49 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 47 def reader? %w[attr_reader attr_accessor].include?(name) end |
#symbols ⇒ Array<String>
Returns the declared symbol names.
42 43 44 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 42 def symbols node.arguments.map { |arg| arg.value.to_s if arg.type == :sym }.compact end |
#writer? ⇒ Boolean
Returns true for attr_writer and attr_accessor.
52 53 54 |
# File 'lib/rubyzen/declarations/attribute_declaration.rb', line 52 def writer? %w[attr_writer attr_accessor].include?(name) end |