Class: Mutant::Context::Scope
- Inherits:
-
Mutant::Context
- Object
- Mutant::Context
- Mutant::Context::Scope
- Extended by:
- AST::Sexp
- Includes:
- Adamantium::Flat
- Defined in:
- lib/mutant/context/scope.rb
Overview
Scope context for mutation (Class or Module)
Constant Summary collapse
- NAMESPACE_DELIMITER =
'::'.freeze
Instance Attribute Summary collapse
-
#scope ⇒ ::Module|::Class
readonly
private
Scope wrapped by context.
Class Method Summary collapse
-
.wrap(scope, node) ⇒ Parser::AST::Class, Parser::AST::Module
private
Wrap node into ast node.
Instance Method Summary collapse
-
#identification ⇒ String
private
Identification string.
-
#match_expressions ⇒ Enumerable<Expression>
private
Match expressions for scope.
-
#nesting ⇒ Enumerable<Class,Module>
private
Nesting of scope.
-
#root(node) ⇒ Parser::AST::Node
private
Return root node for mutation.
-
#unqualified_name ⇒ String
private
Unqualified name of scope.
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.
Scope wrapped by context
96 97 98 |
# File 'lib/mutant/context/scope.rb', line 96 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
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mutant/context/scope.rb', line 42 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) else fail "Cannot wrap scope: #{scope.inspect}" end end |
Instance Method Details
#identification ⇒ 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.
Identification string
26 27 28 |
# File 'lib/mutant/context/scope.rb', line 26 def identification scope.name end |
#match_expressions ⇒ Enumerable<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
82 83 84 85 86 87 88 |
# File 'lib/mutant/context/scope.rb', line 82 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 |
#nesting ⇒ Enumerable<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
59 60 61 62 63 64 65 |
# File 'lib/mutant/context/scope.rb', line 59 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 root node for mutation
15 16 17 18 19 |
# File 'lib/mutant/context/scope.rb', line 15 def root(node) nesting.reverse.reduce(node) do |current, scope| self.class.wrap(scope, current) end end |
#unqualified_name ⇒ 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.
Unqualified name of scope
73 74 75 |
# File 'lib/mutant/context/scope.rb', line 73 def unqualified_name name_nesting.last end |