-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrails.rb
More file actions
34 lines (25 loc) · 818 Bytes
/
trails.rb
File metadata and controls
34 lines (25 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
if ARGV.count == 0 || ARGV[0].downcase.gsub('--', '') == 'help'
puts "Usage: ruby trails.rb [controller#action]"
exit
end
# ruby trails.rb products#index
# CHALLENGE:
#
# Support the above usage. Controller files should
# follow Rails naming conventions, i.e. products_controller.rb
# and action methods should be instance methods.
# Some things you might need:
#
# Kernel.const_get
# Object#send
# get "/directors" => "directors#index"
def invoke_action(target)
controller, action = target.split('#')
controller_file = "#{controller}_controller"
# require "./#{controller_file}"
require_relative controller_file
controller_class = Kernel.const_get("#{controller.capitalize}Controller")
controller_instance = controller_class.new
result = controller_instance.send(action)
puts result
end