Sha256: aa49aca2374f4f8cf0393e11a5d013fe344745e99464bc72fdb7080024aea3b2

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Mutant
  # An abstract context where mutations can be applied to.
  class Context
    include Adamantium, Anima.new(:constant_scope, :scope, :source_path)

    class ConstantScope
      include AST::Sexp

      class Class < self
        include Anima.new(:const, :descendant)

        def call(node)
          s(:class, const, nil, descendant.call(node))
        end
      end

      class Module < self
        include Anima.new(:const, :descendant)

        def call(node)
          s(:module, const, descendant.call(node))
        end
      end

      class None < self
        include Equalizer.new

        def call(node)
          node
        end
      end
    end

    def match_expressions
      scope.match_expressions
    end

    # Return root node for mutation
    #
    # @return [Parser::AST::Node]
    def root(node)
      constant_scope.call(node)
    end

    # Identification string
    #
    # @return [String]
    def identification
      scope.raw.name
    end

  end # Context
end # Mutant

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mutant-0.12.4 lib/mutant/context.rb
mutant-0.12.3 lib/mutant/context.rb
mutant-0.12.2 lib/mutant/context.rb
mutant-0.12.0 lib/mutant/context.rb
mutant-0.11.34 lib/mutant/context.rb
mutant-0.11.33 lib/mutant/context.rb
mutant-0.11.32 lib/mutant/context.rb
mutant-0.11.31 lib/mutant/context.rb
mutant-0.11.30 lib/mutant/context.rb
mutant-0.11.29 lib/mutant/context.rb