Class: RuboCop::Cop::Style::BisectedAttrAccessor::Macro Private
- Inherits:
-
Object
- Object
- RuboCop::Cop::Style::BisectedAttrAccessor::Macro
- Includes:
- VisibilityHelp
- Defined in:
- lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Representation of an ‘attr_reader`, `attr_writer` or `attr` macro for use by `Style/BisectedAttrAccessor`.
Constant Summary
Constants included from VisibilityHelp
VisibilityHelp::VISIBILITY_SCOPES
Instance Attribute Summary collapse
- #attrs ⇒ Object readonly private
- #bisection ⇒ Object readonly private
- #node ⇒ Object readonly private
Class Method Summary collapse
- .macro?(node) ⇒ Boolean private
Instance Method Summary collapse
- #all_bisected? ⇒ Boolean private
- #attr_names ⇒ Object private
- #bisect(*names) ⇒ Object private
- #bisected_names ⇒ Object private
-
#initialize(node) ⇒ Macro
constructor
private
A new instance of Macro.
- #reader? ⇒ Boolean private
- #rest ⇒ Object private
- #visibility ⇒ Object private
- #writer? ⇒ Boolean private
Constructor Details
#initialize(node) ⇒ Macro
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Macro.
19 20 21 22 23 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 19 def initialize(node) @node = node @attrs = node.arguments.to_h { |attr| [attr.source, attr] } @bisection = [] end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 13 def attrs @attrs end |
#bisection ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 13 def bisection @bisection end |
#node ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 13 def node @node end |
Class Method Details
.macro?(node) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 15 def self.macro?(node) node.method?(:attr_reader) || node.method?(:attr_writer) || node.method?(:attr) end |
Instance Method Details
#all_bisected? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 50 51 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 49 def all_bisected? rest.none? end |
#attr_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 30 31 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 29 def attr_names @attr_names ||= attrs.keys end |
#bisect(*names) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 25 def bisect(*names) @bisection = attrs.slice(*names).values end |
#bisected_names ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 33 def bisected_names bisection.map(&:source) end |
#reader? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 41 def reader? node.method?(:attr_reader) || node.method?(:attr) end |
#rest ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 53 def rest @rest ||= attr_names - bisected_names end |
#visibility ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
37 38 39 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 37 def visibility @visibility ||= node_visibility(node) end |
#writer? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 45 def writer? node.method?(:attr_writer) end |