Sha256: ff678602490d306da9b320fd8d614a4c8822e29be6cc2d9db06824880e6c556e

Contents?: true

Size: 1.35 KB

Versions: 193

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      class BisectedAttrAccessor
        # Representation of an `attr_reader`, `attr_writer` or `attr` macro
        # for use by `Style/BisectedAttrAccessor`.
        # @api private
        class Macro
          include VisibilityHelp

          attr_reader :node, :attrs, :bisection

          def self.macro?(node)
            node.method?(:attr_reader) || node.method?(:attr_writer) || node.method?(:attr)
          end

          def initialize(node)
            @node = node
            @attrs = node.arguments.to_h { |attr| [attr.source, attr] }
            @bisection = []
          end

          def bisect(*names)
            @bisection = attrs.slice(*names).values
          end

          def attr_names
            @attr_names ||= attrs.keys
          end

          def bisected_names
            bisection.map(&:source)
          end

          def visibility
            @visibility ||= node_visibility(node)
          end

          def reader?
            node.method?(:attr_reader) || node.method?(:attr)
          end

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

          def all_bisected?
            rest.none?
          end

          def rest
            @rest ||= attr_names - bisected_names
          end
        end
      end
    end
  end
end

Version data entries

193 entries across 186 versions & 18 rubygems

Version Path
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/style/bisected_attr_accessor/macro.rb