Class: Bwrap::Config::Features::Ruby
- Includes:
- Execution
- Defined in:
- lib/bwrap/config/features/ruby.rb
Overview
Defines Ruby feature set.
Implies Nscd feature.
Instance Method Summary collapse
-
#enable ⇒ Object
Enable Ruby feature set.
-
#gem_env_paths? ⇒ Boolean
True if bindirs from “gem environment” should be added to sandbox.
-
#initialize(features) ⇒ Ruby
constructor
A new instance of Ruby.
-
#interpreter ⇒ Pathname|nil
Path to Ruby interpreter.
-
#ruby_config ⇒ Hash(String, String)
RbConfig::CONFIG from interpreter returned by #interpreter.
-
#stdlib ⇒ Array
Extra libraries to be loaded from script’s interpreter’s ‘RbConfig::CONFIG`.
- #stdlib=(libs) ⇒ Object
Methods included from Execution
do_execute, last_status, popen2e
Methods included from Output
debug?, debug_output, error_output, handle_output_options, info_output, quiet?, trace?, trace_output, verb_output, verbose?, warn_output
Methods inherited from Base
Constructor Details
#initialize(features) ⇒ Ruby
Returns a new instance of Ruby.
11 12 13 14 15 16 |
# File 'lib/bwrap/config/features/ruby.rb', line 11 def initialize features super features @gem_env_paths = true @stdlib = [] end |
Instance Method Details
#enable ⇒ Object
This does not allow development headers needed for compilation for now. I’ll look at it after I have an use for it.
Also enables Nscd feature.
Enable Ruby feature set.
Among others, binds ‘RbConfig::CONFIG` so scripts works.
31 32 33 34 35 |
# File 'lib/bwrap/config/features/ruby.rb', line 31 def enable super @features.nscd.enable end |
#gem_env_paths? ⇒ Boolean
Returns true if bindirs from “gem environment” should be added to sandbox.
19 20 21 |
# File 'lib/bwrap/config/features/ruby.rb', line 19 def gem_env_paths? @gem_env_paths end |
#interpreter ⇒ Pathname|nil
Returns path to Ruby interpreter.
38 39 40 |
# File 'lib/bwrap/config/features/ruby.rb', line 38 def interpreter @features.mime&.executable_path end |
#ruby_config ⇒ Hash(String, String)
Returns RbConfig::CONFIG from interpreter returned by #interpreter.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bwrap/config/features/ruby.rb', line 43 def ruby_config unless interpreter raise "Interpreter is not set, so ruby_config() can’t be called yet." end return @ruby_config if @ruby_config script = %q{RbConfig::CONFIG.each { |k, v| puts "#{k}=#{v}" }} config_string = execvalue %W{ #{interpreter} -e #{script} } ruby_config = {} config_string.split("\n").each do |line| key, value = line.split "=", 2 ruby_config[key] = value end @ruby_config = ruby_config end |
#stdlib ⇒ Array
This is only required to be called if extra dependencies are necessary. For example, psych.so requires libyaml.so.
Extra libraries to be loaded from script’s interpreter’s ‘RbConfig::CONFIG`.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bwrap/config/features/ruby.rb', line 72 def stdlib # Just a little check to have error earlier. @stdlib.each do |lib| unless File.exist? "#{ruby_config["rubyarchdir"]}/#{lib}.so" raise "Library “#{lib}” passed to Bwrap::Config::Ruby.stdlib= does not exist." end end @stdlib end |
#stdlib=(libs) ⇒ Object
83 84 85 |
# File 'lib/bwrap/config/features/ruby.rb', line 83 def stdlib= libs @stdlib = libs end |