Class: BiorubyController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb

Constant Summary collapse

HIDE_METHODS =
Object.methods + [ "singleton_method_added" ]
HIDE_MODULES =
[
  Base64::Deprecated, Base64, PP::ObjectMixin, Bio::Shell,
]
HIDE_VARIABLES =
[
  "_", "irb", "_erbout",
]
SECURITY_NOTICE =
"For security purposes, this functionality is only available to local requests."

Instance Method Summary collapse

Instance Method Details

#commandsObject



135
136
137
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 135

def commands
  @bioruby_commands = Bio::Shell.private_instance_methods.sort
end

#evaluateObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 22

def evaluate
  if local_request?
    begin
      @script = params[:script].strip

      # write out to history
      Bio::Shell.store_history(@script)

      # evaluate ruby script
      @result = eval(@script, Bio::Shell.cache[:binding])

      # *TODO* need to handle with output of print/puts/p/pp etc. here
      @output = nil
    rescue
      @result = $!
      @output = nil
    end
  else
    @result = SECURITY_NOTICE
    @output = nil
  end

  @number = Bio::Shell.cache[:results].store(@script, @result, @output)

  render :update do |page|
    render_log(page)
  end
end

#historyObject



139
140
141
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 139

def history
  @history = File.readlines(Bio::Shell.history_file)
end

#indexObject



16
17
18
19
20
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 16

def index
  unless local_request?
    flash[:notice] = SECURITY_NOTICE
  end
end

#list_classesObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 64

def list_classes
  number = params[:number].to_i

  script, result, output = Bio::Shell.cache[:results].restore(number)
  class_name = result.class
  @class = class_name
  @classes = []
  loop do
    @classes.unshift(class_name)
    if class_name == Object
      break
    else
      class_name = class_name.superclass
    end
  end

  render :update do |page|
    page.replace_html "classes_#{number}", :partial => "classes"
    page.visual_effect :toggle_blind, "classes_#{number}", :duration => 0.5
  end
end

#list_methodsObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 51

def list_methods
  number = params[:number].to_i

  script, result, output = Bio::Shell.cache[:results].restore(number)
  @class = result.class
  @methods = (result.methods - HIDE_METHODS).sort

  render :update do |page|
    page.replace_html "methods_#{number}", :partial => "methods"
    page.visual_effect :toggle_blind, "methods_#{number}", :duration => 0.5
  end
end

#list_modulesObject



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 86

def list_modules
  number = params[:number].to_i

  script, result, output = Bio::Shell.cache[:results].restore(number)
  @class = result.class
  @modules = result.class.included_modules - HIDE_MODULES

  render :update do |page|
    page.replace_html "modules_#{number}", :partial => "modules"
    page.visual_effect :toggle_blind, "modules_#{number}", :duration => 0.5
  end
end

#reload_scriptObject



99
100
101
102
103
104
105
106
107
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 99

def reload_script
  number = params[:number].to_i

  script, result, output = Bio::Shell.cache[:results].restore(number)

  render :update do |page|
    page.replace_html :script, script
  end
end

#resultsObject



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/bio/shell/rails/vendor/plugins/bioruby/generators/bioruby/templates/bioruby_controller.rb', line 109

def results
  if Bio::Shell.cache[:results].number > 0
    limit = params[:limit].to_i
    max_num = Bio::Shell.cache[:results].number
    min_num = [ max_num - limit + 1, 1 ].max
    min_num = 1 if limit == 0

    render :update do |page|
      # delete all existing results in the current DOM for clean up
      page.select(".log").each do |element|
        #page.hide element
        page.remove element
      end

      # add selected results to the current DOM
      min_num.upto(max_num) do |@number|
        #page.show "log_#{@number}"
        @script, @result, @output = Bio::Shell.cache[:results].restore(@number)
        if @script
          render_log(page)
        end
      end
    end
  end
end