Sha256: a1e1c886465a6a713cb7deb8a3b20ff28bdc3fa90cfd29c41a561a83e5679f94

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

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

        def receiver
          children.first
        end

        def name
          children[1]
        end

        def args
          children[2..-1]
        end

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

        def arg_names
          args.map { |arg| arg.children.first }
        end

        def module_creation_call?
          object_creation_call? && module_creation_receiver?
        end

        def module_creation_receiver?
          receiver && [: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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
reek-3.10.0 lib/reek/ast/sexp_extensions/send.rb
reek-3.9.1 lib/reek/ast/sexp_extensions/send.rb
reek-3.9.0 lib/reek/ast/sexp_extensions/send.rb