Sha256: 74c0da8225694ef213070a6c04785fad49f4506eb2cc1270a7765f9f0b988cac

Contents?: true

Size: 1.19 KB

Versions: 5

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Reek
  module AST
    module SexpExtensions
      # Utility methods for :send nodes.
      module SendNode
        ATTR_DEFN_METHODS = [:attr_writer, :attr_accessor].freeze

        def receiver
          children.first
        end

        def name
          children[1]
        end

        def args
          children[2..]
        end

        def participants
          ([receiver] + args).compact
        end

        def module_creation_call?
          object_creation_call? && module_creation_receiver?
        end

        def module_creation_receiver?
          receiver &&
            receiver.type == :const &&
            [:Class, :Struct].include?(receiver.simple_name)
        end

        def object_creation_call?
          name == :new
        end

        def attribute_writer?
          ATTR_DEFN_METHODS.include?(name) ||
            attr_with_writable_flag?
        end

        # Handles the case where we create an attribute writer via:
        # attr :foo, true
        def attr_with_writable_flag?
          name == :attr && args.any? && args.last.type == :true
        end
      end

      Op_AsgnNode = SendNode
      CSendNode = SendNode
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reek-6.1.4 lib/reek/ast/sexp_extensions/send.rb
reek-6.1.3 lib/reek/ast/sexp_extensions/send.rb
reek-6.1.2 lib/reek/ast/sexp_extensions/send.rb
reek-6.1.1 lib/reek/ast/sexp_extensions/send.rb
reek-6.1.0 lib/reek/ast/sexp_extensions/send.rb