Module: ActiveMocker::MockCreator::Scopes
- Includes:
- SafeMethods
- Defined in:
- lib/active_mocker/mock_creator/scopes.rb
Defined Under Namespace
Classes: Method
Constant Summary
Constants included
from SafeMethods
ActiveMocker::MockCreator::SafeMethods::BASE
Instance Method Summary
collapse
#safe_method?
Instance Method Details
#ast_scopes ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 32
def ast_scopes
@ast_scopes ||= class_introspector
.parsed_source
.class_begin
.children
.select { |n| n.try(:type) == :send && n.try { children[1] == :scope } }
end
|
#find_scope_body_from_ast(name) ⇒ Object
40
41
42
43
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 40
def find_scope_body_from_ast(name)
scope = ast_scopes.detect { |n| n.children[2].children.first == name }
DissociatedIntrospection::RubyCode.build_from_ast(scope.children[3].children[2]).source
end
|
#scope_body(_arguments, name) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 18
def scope_body(_arguments, name)
if safe_method?(:scope, name)
find_scope_body_from_ast(name)
else
<<-METHOD
__am_raise_not_mocked_error(
method: "#{name}",
caller: Kernel.caller,
type: "::"
)
METHOD
end
end
|
#scope_methods ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 9
def scope_methods
class_introspector.class_macros.select { |h| h.keys.first == :scope }.map do |h|
name, args = h.values.first.first
arguments = ReverseParameters.new(args)
body = scope_body(arguments, name)
Method.new(name, arguments, body)
end
end
|