Class: RuboCop::Cop::Style::BisectedAttrAccessor::Macro Private

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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.map { |attr| [attr.source, attr] }.to_h
  @bisection = []
end

Instance Attribute Details

#attrsObject (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

#bisectionObject (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

#nodeObject (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.

Returns:

  • (Boolean)

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.

Returns:

  • (Boolean)

49
50
51
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 49

def all_bisected?
  rest.none?
end

#attr_namesObject

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_namesObject

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.

Returns:

  • (Boolean)

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

#restObject

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

#visibilityObject

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.

Returns:

  • (Boolean)

45
46
47
# File 'lib/rubocop/cop/style/bisected_attr_accessor/macro.rb', line 45

def writer?
  node.method?(:attr_writer)
end