Class: Mutant::Context::Scope

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

Overview

Scope context for mutation (Class or Module)

Instance Attribute Summary collapse

Attributes inherited from Mutant::Context

#source_path

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (::Module|::Class)


75
76
77
# File 'lib/mutant/context/scope.rb', line 75

def scope
  @scope
end

Class Method Details

.wrap(scope, node) ⇒ Rubinius::AST::Class, Rubinius::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 (Rubinius::AST::Node)

Returns:

  • (Rubinius::AST::Class)

    if scope is of kind Class

  • (Rubinius::AST::Module)

    if scope is of kind module



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mutant/context/scope.rb', line 32

def self.wrap(scope, node)
  name = scope.name.split('::').last.to_sym
  case scope
  when ::Class
    ::Rubinius::AST::Class.new(0, name, nil, node)
  when ::Module
    ::Rubinius::AST::Module.new(0, name, node)
  else
    raise "Cannot wrap scope: #{scope.inspect}"
  end
end

Instance Method Details

#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

Returns:

  • (Enumerable<Class,Module>)


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

def nesting
  const = ::Object
  name_nesting.each_with_object([]) do |name, nesting|
    const = const.const_get(name)
    nesting << const
  end
end

#root(node) ⇒ Rubinius::AST::Script

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

Returns:

  • (Rubinius::AST::Script)


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

def root(node)
  nesting.reverse.inject(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

Returns:

  • (String)


65
66
67
# File 'lib/mutant/context/scope.rb', line 65

def unqualified_name
  name_nesting.last
end