Sha256: 064a0d646e56bf7901696ae35f61e8f53f9b16bcb1edfeb74f2385a51ad5b216

Contents?: true

Size: 1.73 KB

Versions: 28

Compression:

Stored size: 1.73 KB

Contents

# frozen_string_literal: true
module Reek
  module AST
    module SexpExtensions
      # Base module for utility methods for :def and :defs nodes.
      module MethodNodeBase
        def arguments
          parameters.reject(&:block?)
        end

        def arg_names
          arguments.map(&:name)
        end

        def parameters
          argslist.components
        end

        def parameter_names
          parameters.map(&:name)
        end

        def name_without_bang
          name.to_s.chop
        end

        def ends_with_bang?
          name[-1] == '!'
        end

        def body_nodes(types, ignoring = [])
          if body
            body.find_nodes(types, ignoring)
          else
            []
          end
        end
      end

      # Utility methods for :def nodes.
      module DefNode
        include MethodNodeBase

        def name
          children.first
        end

        def argslist
          children[1]
        end

        def body
          children[2]
        end

        def full_name(outer)
          [outer, name].reject(&:empty?).join('#')
        end

        def depends_on_instance?
          ReferenceCollector.new(self).num_refs_to_self > 0
        end
      end

      # Utility methods for :defs nodes.
      module DefsNode
        include MethodNodeBase

        def receiver
          children.first
        end

        def name
          children[1]
        end

        def argslist
          children[2]
        end

        def body
          children[3]
        end

        def full_name(outer)
          prefix = outer == '' ? '' : "#{outer}#"
          "#{prefix}#{receiver.name}.#{name}"
        end

        def depends_on_instance?
          false
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
reek-4.6.1 lib/reek/ast/sexp_extensions/methods.rb
reek-4.6.0 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.6 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.5 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.4 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.3 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.2 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.1 lib/reek/ast/sexp_extensions/methods.rb
reek-4.5.0 lib/reek/ast/sexp_extensions/methods.rb
reek-4.4.2 lib/reek/ast/sexp_extensions/methods.rb
reek-4.4.1 lib/reek/ast/sexp_extensions/methods.rb
reek-4.4.0 lib/reek/ast/sexp_extensions/methods.rb
reek-4.3.0 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.5 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.4 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.3 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.2 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.1 lib/reek/ast/sexp_extensions/methods.rb
reek-4.2.0 lib/reek/ast/sexp_extensions/methods.rb
reek-4.1.1 lib/reek/ast/sexp_extensions/methods.rb