Class: Spektr::Targets::Controller
- Inherits:
-
Base
- Object
- Prism::Visitor
- Base
- Spektr::Targets::Controller
show all
- Defined in:
- lib/spektr/targets/controller.rb
Defined Under Namespace
Classes: Action
Instance Attribute Summary
Attributes inherited from Base
#ast, #calls, #interpolated_xstrings, #lvars, #methods, #name, #options, #parent, #parent_modules, #path
Instance Method Summary
collapse
Methods inherited from Base
#find_calls, #find_calls_with_block, #find_method, #find_methods, #method_definitions, #public_methods, #visit_call_node, #visit_class_node, #visit_def_node, #visit_instance_variable_write_node, #visit_interpolated_x_string_node, #visit_local_variable_write_node, #visit_module_node
Constructor Details
#initialize(path, content) ⇒ Controller
Returns a new instance of Controller.
5
6
7
|
# File 'lib/spektr/targets/controller.rb', line 5
def initialize(path, content)
super
end
|
Instance Method Details
#actions ⇒ Object
13
14
15
16
17
|
# File 'lib/spektr/targets/controller.rb', line 13
def actions
@actions ||= public_methods.map do |node|
Action.new(node, self)
end
end
|
#concern? ⇒ Boolean
9
10
11
|
# File 'lib/spektr/targets/controller.rb', line 9
def concern?
!name.match('Controller')
end
|
#find_action(action) ⇒ Object
19
20
21
|
# File 'lib/spektr/targets/controller.rb', line 19
def find_action(action)
@actions.find{|a| a.name == action }
end
|
#find_in_set(name, set) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/spektr/targets/controller.rb', line 31
def find_in_set(name, set)
while true
result = set.find { |c| c.name == name }
break if result
split = name.split('::')
split.shift
name = split.join('::')
break if name.blank?
end
result
end
|
#find_parent(controllers) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/spektr/targets/controller.rb', line 23
def find_parent(controllers)
result = find_in_set(@parent, controllers)
return nil if result&.name == name
result
end
|