Class: Ruber::RubyRunner::RubyInterpretersPlugin
Overview
The plugin object for the ruby_runner
feature.
This class provides a way to set the ruby interpreter to use, allowing to override the interpreter set globally or for the current project. This choice can be made programmaticaly or by the user, using the “Interpreter” submenu added by this class to the “Ruby” menu.
The interpreters which can be chosen are configured globally by the user.
Constant Summary
Constants inherited from Plugin
Instance Attribute Summary
Attributes included from PluginLike
Instance Method Summary (collapse)
-
- (String?) choose_interpreter(arg)
Sets the ruby interpreter to use.
-
- (String?) chosen_interpreter
The path of the interpreter chosen by the user the default interpreter should be used.
-
- (Object) fill_interpreters_menu
private
Clears and refills the “Interpreters” submenu.
-
- (<String>) find_interpreters
private
Finds the ruby interpreters availlable on the system.
-
- (RubyInterpretersPlugin) initialize(psf)
constructor
Creates a new RubyInterpretersPlugin.
-
- (nil) unload
Override of PluginLike#unload.
Methods inherited from GuiPlugin
#action_collection, #execute_action, #register_action_handler, #setup_actions
Methods inherited from Plugin
Methods included from PluginLike
#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #delayed_initialize, #initialize_plugin, #load_settings, #plugin_name, #query_close, #register_options, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #save_settings, #session_data, #setup_action, #setup_actions, #shutdown, #update_project
API for feature ruby_runner
Methods API
Constructor Details
- (RubyInterpretersPlugin) initialize(psf)
Creates a new RubyInterpretersPlugin. the plugin
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 156 def initialize psf silently do Object.const_set :RubyOptionsWidget, RubyOptionsWidget end super @default_interpreter_action = action_collection.action('ruby_runner-configured_interpreter') @interpreter_actions = [] @interpreters_group = Qt::ActionGroup.new self @interpreters_group.add_action @default_interpreter_action @default_interpreter_action.checked = true end |
Instance Method Details
- (String?) choose_interpreter(arg)
Sets the ruby interpreter to use.
Calling this method will check one of the entries of the “Interpreters” submenu
will be used. If it is a string, it is the path of the interpreter to use. If this doesn’t correspond to one of the entries in the “Interpreters” submenu, nothing is done. be used.
191 192 193 194 195 196 197 198 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 191 def choose_interpreter arg if arg.nil? then @default_interpreter_action.checked = true else action = @interpreters_group.actions.find{|a| a.object_name == arg} action.checked = true if action end chosen_interpreter end |
- (String?) chosen_interpreter
The path of the interpreter chosen by the user the default interpreter should be used
174 175 176 177 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 174 def chosen_interpreter checked = @interpreters_group.checked_action checked.same?( @default_interpreter_action) ? nil : checked.object_name end |
Clears and refills the “Interpreters” submenu
The list of availlable interpreters is read from the ruby/interpreters
config
option
The selection is preserved if possible (that is, if an interpreter with the same path as the previously selected one still exists). If this isn’t possible, the default entry is selected.
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 241 def @gui.unplug_action_list 'ruby_runner-interpreters' old_checked = @interpreters_group.checked_action.object_name @interpreter_actions.each{|a| @interpreters_group.remove_action a} @interpreter_actions.clear @interpreter_actions = Ruber[:config][:ruby, :interpreters].map do |i| a = KDE::ToggleAction.new i, action_collection a.object_name = i @interpreters_group.add_action a a.checked = true if i == old_checked a end @gui.plug_action_list 'ruby_runner-interpreters', @interpreter_actions unless @interpreters_group.checked_action action_collection.action('ruby_runner-configured_interpreter').checked = true end nil end |
- (<String>) find_interpreters (private)
Finds the ruby interpreters availlable on the system.
The interpreters are searched using the which -a
command (this means that only
interpreters in the PATH
environment variable will be found). The names which
are tried are: ruby
, ruby19
, ruby18
, ruby1.9
and ruby1.8
.
the system
224 225 226 227 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 224 def find_interpreters look_for = %w[ruby ruby19 ruby18 ruby1.9 ruby1.8] look_for.map{|r| interpreters = `which #{r} 2> /dev/null`.split_lines}.flatten end |
- (nil) unload
Override of PluginLike#unload
Besides doing the same as the base class method, it also removes the Ruber::RubyRunner::RubyRunnerPlugin
constant, so that other plugins may reimplement it using another base class.
207 208 209 210 |
# File 'plugins/ruby_runner/ruby_runner.rb', line 207 def unload Ruber::RubyRunner.send :remove_const, :RubyRunnerPlugin super end |