Class: CompassAeConsole::ErpApp::Desktop::BaseController

Inherits:
ErpApp::Desktop::BaseController
  • Object
show all
Defined in:
app/controllers/compass_ae_console/erp_app/desktop/base_controller.rb

Instance Method Summary collapse

Instance Method Details

#commandObject



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
35
36
37
38
39
40
41
42
# File 'app/controllers/compass_ae_console/erp_app/desktop/base_controller.rb', line 5

def command
  begin
    result = ""

    # NOTE- the console uses a shared binding. this is due to the fact
    # that binding instances are not serializable and cant be stored
    # in a user session. Until this is resolved we use a global var.
    # this should not pose a problem as the console should only be used
    # in development or by a sysadmin. 

    # the shared binding is needed to allow for variable scope visibility
    # across multiple requests 
    if ($session_binding==nil)
      $session_binding=binding
    end

    command_message=params[:command_message]

    # here we handle any desktop console-specific command
    # these can include non-eval related funtions
    # or provide shortcuts to common eval expressions
    result = case command_message
               when /^-help/
                 help_message
               when /^-clear/
                 #this is handled in the console desktop application
               when /^-time/
                 evaluate_command("Time.now")
               when /^-whoami/
                 evaluate_command("current_user.username")
               else
                 evaluate_command(command_message)
             end

    result_message = result.to_s.gsub("\n", "<br />\n")
    render :json => {:success => "#{result_message}<hr><br>"}
  end
end