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_methods
Instance Method Details
#ast_scopes ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 29
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
37
38
39
40
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 37
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
|
# File 'lib/active_mocker/mock_creator/scopes.rb', line 18
def scope_body(arguments, name)
if safe_methods[:scopes].include?(name)
find_scope_body_from_ast(name)
else
"#{class_name}.send(:call_mock_method, " \
"method: '#{name}', " \
"caller: Kernel.caller, " \
"arguments: [#{arguments.arguments}])"
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
|