Module: Reek::AST::SexpExtensions::SendNode

Defined in:
lib/reek/ast/sexp_extensions/send.rb

Overview

Utility methods for :send nodes.

Constant Summary collapse

ATTR_DEFN_METHODS =
[:attr_writer, :attr_accessor].freeze

Instance Method Summary collapse

Instance Method Details

#argsObject



18
19
20
# File 'lib/reek/ast/sexp_extensions/send.rb', line 18

def args
  children[2..]
end

#attr_with_writable_flag?Boolean

Handles the case where we create an attribute writer via: attr :foo, true

Returns:

  • (Boolean)


44
45
46
# File 'lib/reek/ast/sexp_extensions/send.rb', line 44

def attr_with_writable_flag?
  name == :attr && args.any? && args.last.type == :true
end

#attribute_writer?Boolean

Returns:

  • (Boolean)


37
38
39
40
# File 'lib/reek/ast/sexp_extensions/send.rb', line 37

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

#const_receiver?Boolean (private)

Returns:

  • (Boolean)


62
63
64
# File 'lib/reek/ast/sexp_extensions/send.rb', line 62

def const_receiver?
  receiver && receiver.type == :const
end

#data_definition_call?Boolean (private)

Returns:

  • (Boolean)


54
55
56
# File 'lib/reek/ast/sexp_extensions/send.rb', line 54

def data_definition_call?
  name == :define
end

#data_definition_receiver?Boolean (private)

Returns:

  • (Boolean)


58
59
60
# File 'lib/reek/ast/sexp_extensions/send.rb', line 58

def data_definition_receiver?
  const_receiver? && receiver.simple_name == :Data
end

#module_creation_call?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
# File 'lib/reek/ast/sexp_extensions/send.rb', line 26

def module_creation_call?
  return true if object_creation_call? && module_creation_receiver?
  return true if data_definition_call? && data_definition_receiver?

  false
end

#module_creation_receiver?Boolean (private)

Returns:

  • (Boolean)


50
51
52
# File 'lib/reek/ast/sexp_extensions/send.rb', line 50

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

#nameObject



14
15
16
# File 'lib/reek/ast/sexp_extensions/send.rb', line 14

def name
  children[1]
end

#object_creation_call?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/reek/ast/sexp_extensions/send.rb', line 33

def object_creation_call?
  name == :new
end

#participantsObject



22
23
24
# File 'lib/reek/ast/sexp_extensions/send.rb', line 22

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

#receiverObject



10
11
12
# File 'lib/reek/ast/sexp_extensions/send.rb', line 10

def receiver
  children.first
end