Class: Mutant::Context::Scope

Inherits:
Mutant::Context show all
Extended by:
NodeHelpers
Includes:
Adamantium::Flat
Defined in:
lib/mutant/context/scope.rb

Overview

Scope context for mutation (Class or Module)

Constant Summary

Constants included from NodeHelpers

NodeHelpers::INFINITY, NodeHelpers::NAN, NodeHelpers::NEGATIVE_INFINITY, NodeHelpers::NEW_OBJECT, NodeHelpers::N_EMPTY, NodeHelpers::N_FALSE, NodeHelpers::N_NIL, NodeHelpers::N_TRUE, NodeHelpers::RAISE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeHelpers

n_not, s

Instance Attribute Details

#scope::Module|::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.

Return scope wrapped by context



111
112
113
# File 'lib/mutant/context/scope.rb', line 111

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



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mutant/context/scope.rb', line 45

def self.wrap(scope, node)
  name = s(:const, nil, scope.name.split('::').last.to_sym)
  case scope
  when ::Class
    s(:class, name, nil, node)
  when ::Module
    s(:module, name, node)
  else
    raise "Cannot wrap scope: #{scope.inspect}"
  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.

Return identification



28
29
30
# File 'lib/mutant/context/scope.rb', line 28

def identification
  scope.name
end

#match_prefixesEnumerable<String>

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 match prefixes



98
99
100
101
102
# File 'lib/mutant/context/scope.rb', line 98

def match_prefixes
  name_nesting.each_index.reverse_each.map do |index|
    name_nesting.take(index.succ).join('::')
  end
end

#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.

Return name



88
89
90
# File 'lib/mutant/context/scope.rb', line 88

def name
  scope.name
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.

Return nesting



63
64
65
66
67
68
69
# File 'lib/mutant/context/scope.rb', line 63

def nesting
  const = ::Object
  name_nesting.each_with_object([]) do |name, nesting|
    const = const.const_get(name)
    nesting << const
  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 AST wrapping mutated node



16
17
18
19
20
# File 'lib/mutant/context/scope.rb', line 16

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.

Return unqualified name of scope



78
79
80
# File 'lib/mutant/context/scope.rb', line 78

def unqualified_name
  name_nesting.last
end