Class: CommandlineController

Inherits:
ApplicationController show all
Defined in:
app/controllers/commandline_controller.rb

Overview

Controller for command line thingies

Direct Known Subclasses

SugoiAdminController

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/commandline_controller.rb', line 20

def method_missing(meth, *params)
    possibles=action_methods.grep(/^#{meth}/)
    case possibles.length
    when 0
        raise UnknownAction, "No action responded to #{action_name}", caller
    when 1
        self.action_name = possibles[0]
        send(possibles[0], *params)
    else
        raise UnknownAction, "More than one command starts with #{meth}"
    end
end

Instance Method Details

#perform_actionObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/commandline_controller.rb', line 8

def perform_action
    if self.class.action_methods.include?(action_name.to_s) || 
       self.class.action_methods.include?('method_missing')
        @exitcode = send(action_name,*params["args"]) || 0
        render unless performed?
    elsif template_exists? && template_public?
        render
    else
        raise UnknownAction, "No action responded to #{action_name}", caller
    end
end