Sha256: 8348b43078141d4a10aee9d0d691a87493a52574dbef1203c5317051ace2de10

Contents?: true

Size: 1.78 KB

Versions: 25

Compression:

Stored size: 1.78 KB

Contents

# frozen_string_literal: true

module Mutant
  module AST
    # Node meta information mixin
    module Meta

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

        children :receiver, :selector

        public :receiver, :selector

        INDEX_ASSIGNMENT_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.to_s.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(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(receiver).name.equal?(:Proc)
        end

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mutant-0.10.20 lib/mutant/ast/meta/send.rb
mutant-0.10.19 lib/mutant/ast/meta/send.rb
mutant-0.10.18 lib/mutant/ast/meta/send.rb
mutant-0.10.17 lib/mutant/ast/meta/send.rb
mutant-0.10.16 lib/mutant/ast/meta/send.rb
mutant-0.10.15 lib/mutant/ast/meta/send.rb
mutant-0.10.14 lib/mutant/ast/meta/send.rb
mutant-0.10.13 lib/mutant/ast/meta/send.rb
mutant-0.10.12 lib/mutant/ast/meta/send.rb
mutant-0.10.11 lib/mutant/ast/meta/send.rb
mutant-0.10.10 lib/mutant/ast/meta/send.rb
mutant-0.10.9 lib/mutant/ast/meta/send.rb
mutant-0.10.8 lib/mutant/ast/meta/send.rb
mutant-0.10.7 lib/mutant/ast/meta/send.rb
mutant-0.10.6 lib/mutant/ast/meta/send.rb
mutant-0.10.5 lib/mutant/ast/meta/send.rb
mutant-0.10.4 lib/mutant/ast/meta/send.rb
mutant-0.10.1 lib/mutant/ast/meta/send.rb
mutant-0.10.0 lib/mutant/ast/meta/send.rb
mutant-0.9.14 lib/mutant/ast/meta/send.rb