Class: Mutant::Context Private

Inherits:
Object
  • Object
show all
Extended by:
AST::Sexp
Includes:
Unparser::Adamantium
Defined in:
lib/mutant/context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An abstract context where mutations can be applied to.

Constant Summary collapse

NAMESPACE_DELIMITER =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'::'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#scopeModule|Class (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Scope wrapped by context

Returns:

  • (Module|Class)


80
81
82
# File 'lib/mutant/context.rb', line 80

def scope
  @scope
end

Class Method Details

.wrap(scope, node) ⇒ Parser::AST::Class, Parser::AST::Module

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wrap node into ast node

Parameters:

  • scope (Class, Module)
  • node (Parser::AST::Node)

Returns:

  • (Parser::AST::Class)

    if scope is of kind Class

  • (Parser::AST::Module)

    if scope is of kind module



37
38
39
40
41
42
43
44
45
# File 'lib/mutant/context.rb', line 37

def self.wrap(scope, node)
  name = s(:const, nil, scope.name.split(NAMESPACE_DELIMITER).last.to_sym)
  case scope
  when Class
    s(:class, name, nil, node)
  when Module
    s(:module, name, node)
  end
end

Instance Method Details

#identificationString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Identification string

Returns:

  • (String)


23
24
25
# File 'lib/mutant/context.rb', line 23

def identification
  scope.name
end

#match_expressionsEnumerable<Expression>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Match expressions for scope

Returns:



68
69
70
71
72
73
74
# File 'lib/mutant/context.rb', line 68

def match_expressions
  name_nesting.each_index.reverse_each.map do |index|
    Expression::Namespace::Recursive.new(
      scope_name: name_nesting.take(index.succ).join(NAMESPACE_DELIMITER)
    )
  end
end

#nestingEnumerable<Class,Module>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Nesting of scope

Returns:

  • (Enumerable<Class,Module>)


50
51
52
53
54
55
# File 'lib/mutant/context.rb', line 50

def nesting
  const = Object
  name_nesting.map do |name|
    const = const.const_get(name)
  end
end

#root(node) ⇒ Parser::AST::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return root node for mutation

Returns:

  • (Parser::AST::Node)


14
15
16
17
18
# File 'lib/mutant/context.rb', line 14

def root(node)
  nesting.reverse.reduce(node) do |current, scope|
    self.class.wrap(scope, current)
  end
end

#unqualified_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Unqualified name of scope

Returns:

  • (String)


61
62
63
# File 'lib/mutant/context.rb', line 61

def unqualified_name
  name_nesting.last
end