Sha256: 679e148240e6b46b08084d930eaf657932fa4bfe5d76a4fe1e30303abc5971d5

Contents?: true

Size: 1.1 KB

Versions: 8

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Reek
  module AST
    module SexpExtensions
      # Utility methods for :if nodes.
      module IfNode
        #
        # @return [Reek::AST::Node] the condition that is associated with a conditional node.
        #   For instance, this code
        #
        #     if charlie(bravo) then delta end
        #
        #   would be parsed into this AST:
        #
        #     s(:if,
        #       s(:send, nil, :charlie,
        #         s(:lvar, :bravo)),
        #       s(:send, nil, :delta), nil)
        #
        #   so in this case we would return this
        #
        #     s(:send, nil, :charlie,
        #       s(:lvar, :bravo))
        #
        #   as condition.
        #
        def condition
          children.first
        end

        # @quality :reek:FeatureEnvy
        def body_nodes(type, ignoring = [])
          children[1..].compact.flat_map do |child|
            if ignoring.include? child.type
              []
            else
              child.each_node(type, ignoring | type).to_a
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reek-6.4.0 lib/reek/ast/sexp_extensions/if.rb
reek-6.3.0 lib/reek/ast/sexp_extensions/if.rb
reek-6.2.0 lib/reek/ast/sexp_extensions/if.rb
reek-6.1.4 lib/reek/ast/sexp_extensions/if.rb
reek-6.1.3 lib/reek/ast/sexp_extensions/if.rb
reek-6.1.2 lib/reek/ast/sexp_extensions/if.rb
reek-6.1.1 lib/reek/ast/sexp_extensions/if.rb
reek-6.1.0 lib/reek/ast/sexp_extensions/if.rb