Class: Jets::Commands::Call::AnonymousGuesser
Instance Method Summary
collapse
Methods inherited from BaseGuesser
#class_name, #function_name, #initialize
Instance Method Details
#detect_class_name ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/jets/commands/call/anonymous_guesser.rb', line 3
def detect_class_name
found_path = function_paths.find do |path|
File.exist?("#{Jets.root}#{path}")
end
klass = Jets::Klass.from_path(found_path) if found_path
klass.to_s
end
|
#error_message ⇒ Object
Useful to printing out what was attempted to look up
28
29
30
31
32
33
34
35
36
|
# File 'lib/jets/commands/call/anonymous_guesser.rb', line 28
def error_message
guess_paths = function_paths
puts "Unable to find the function to call."
if class_name and !method_name
puts @method_name_error
else
puts "Tried: #{guess_paths.join(', ')}"
end
end
|
#function_filenames(meth = nil, primary_namespace = nil) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/jets/commands/call/anonymous_guesser.rb', line 38
def function_filenames(meth=nil, primary_namespace=nil)
guesses = []
parts = meth.split('_')
if primary_namespace.nil?
guesses << meth
if parts.size == 1 return guesses else
next_primary_namespace = parts.first
guesses += function_filenames(meth, next_primary_namespace) return guesses end
end
next_meth = meth.sub("#{primary_namespace}_", '')
next_parts = next_meth.split('_')
n = next_parts.size + 1
next_parts.size.times do |i|
namespace = i == 0 ? nil : next_parts[0..i-1].join('/')
class_path = next_parts[i..-1].join('_')
guesses << [primary_namespace, namespace, class_path].compact.join('/')
end
final_primary_namespace = parts[0..-2].join('_')
if primary_namespace == final_primary_namespace
return guesses else
namespace_size = parts.size - next_parts.size
next_primary_namespace = parts[0..namespace_size].join('_')
guesses += function_filenames(meth, next_primary_namespace)
return guesses
end
end
|
#function_paths ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/jets/commands/call/anonymous_guesser.rb', line 86
def function_paths
starting_filename = @provided_function_name.underscore.split('_')[0..-2].join('_')
filenames = function_filenames(starting_filename)
filenames.map do |name|
"app/functions/#{name}.rb"
end
end
|
#method_name ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/jets/commands/call/anonymous_guesser.rb', line 12
def method_name
return @method_name if defined?(@method_name)
full_function_name = @provided_function_name.underscore
underscored_class_name = class_name.underscore
meth = full_function_name.sub("#{underscored_class_name}_","")
if meth == class_name.constantize.handler.to_s
@method_name = meth
else
@method_name_error = "#{class_name} class found but #{meth} method not found"
@method_name = nil
end
end
|