Sha256: a73ba72d5aca6d441d8ae738f0397afef489c716ed9a9bb857c6d931bea4c2a7

Contents?: true

Size: 1.73 KB

Versions: 18

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true

module Mutant
  class AST
    # Node meta information mixin
    module Meta

      # Metadata for send nodes
      class Send
        include NamedChildren, Anima.new(:node), NodePredicates

        children :receiver, :selector

        public :receiver, :selector

        ATTRIBUTE_ASSIGNMENT_SELECTOR_SUFFIX = '='

        # Arguments of mutated node
        #
        # @return [Enumerable<Parser::AST::Node>]
        alias_method :arguments, :remaining_children

        public :arguments

        # Test if node is defining a proc
        #
        # @return [Boolean]
        def proc?
          naked_proc? || proc_new?
        end

        # Test if AST node is a valid attribute assignment
        #
        # @return [Boolean]
        def attribute_assignment?
          !Types::METHOD_OPERATORS.include?(selector) && selector.end_with?(ATTRIBUTE_ASSIGNMENT_SELECTOR_SUFFIX)
        end

        # Test for binary operator implemented as method
        #
        # @return [Boolean]
        def binary_method_operator?
          Types::BINARY_METHOD_OPERATORS.include?(selector)
        end

        # Test if receiver is possibly a top level constant
        #
        # @return [Boolean]
        def receiver_possible_top_level_const?
          return false unless receiver && n_const?(receiver)

          Const.new(node: receiver).possible_top_level?
        end

      private

        def naked_proc?
          !receiver && selector.equal?(:proc)
        end

        def proc_new?
          receiver                &&
            selector.equal?(:new) &&
            n_const?(receiver)    &&
            Const.new(node: receiver).name.equal?(:Proc)
        end

      end # Send
    end # Meta
  end # AST
end # Mutant

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mutant-0.12.4 lib/mutant/ast/meta/send.rb
mutant-0.12.3 lib/mutant/ast/meta/send.rb
mutant-0.12.2 lib/mutant/ast/meta/send.rb
mutant-0.12.0 lib/mutant/ast/meta/send.rb
mutant-0.11.34 lib/mutant/ast/meta/send.rb
mutant-0.11.33 lib/mutant/ast/meta/send.rb
mutant-0.11.32 lib/mutant/ast/meta/send.rb
mutant-0.11.31 lib/mutant/ast/meta/send.rb
mutant-0.11.30 lib/mutant/ast/meta/send.rb
mutant-0.11.29 lib/mutant/ast/meta/send.rb
mutant-0.11.28 lib/mutant/ast/meta/send.rb
mutant-0.11.27 lib/mutant/ast/meta/send.rb
mutant-0.11.26 lib/mutant/ast/meta/send.rb
mutant-0.11.25 lib/mutant/ast/meta/send.rb
mutant-0.11.24 lib/mutant/ast/meta/send.rb
mutant-0.11.23 lib/mutant/ast/meta/send.rb
mutant-0.11.22 lib/mutant/ast/meta/send.rb
mutant-0.11.21 lib/mutant/ast/meta/send.rb