Module: Pik::BatchFileEditor
Instance Attribute Summary collapse
-
#batch ⇒ Object
readonly
Returns the value of attribute batch.
Instance Method Summary collapse
- #close ⇒ Object
- #echo_ruby_version(path, verb = '') ⇒ Object
- #echo_running_with_ruby_version(path) ⇒ Object
- #initialize(args = ARGV, config = nil) ⇒ Object
- #set(items) ⇒ Object
- #switch_gem_home_to(gem_home) ⇒ Object
- #switch_path_to(other) ⇒ Object
- #update_gem_batch ⇒ Object
Instance Attribute Details
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
5 6 7 |
# File 'lib/pik/commands/batch_file_editor.rb', line 5 def batch @batch end |
Instance Method Details
#close ⇒ Object
14 15 16 17 |
# File 'lib/pik/commands/batch_file_editor.rb', line 14 def close update_gem_batch super end |
#echo_ruby_version(path, verb = '') ⇒ Object
47 48 49 50 |
# File 'lib/pik/commands/batch_file_editor.rb', line 47 def echo_ruby_version(path, verb='') rb = Which::Ruby.exe(path).basename @batch.file_data << "for /f \"delims=\" %%a in ('#{rb} -v') do @echo #{verb} %%a " end |
#echo_running_with_ruby_version(path) ⇒ Object
52 53 54 |
# File 'lib/pik/commands/batch_file_editor.rb', line 52 def echo_running_with_ruby_version(path) echo_ruby_version('Running with') end |
#initialize(args = ARGV, config = nil) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/pik/commands/batch_file_editor.rb', line 7 def initialize(args=ARGV,config=nil) super batch_file = File.join(PIK_HOME, "#{File.basename($0)}_#{$$}.bat") @batch = BatchFile.new( batch_file ) editors << @batch end |
#set(items) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/pik/commands/batch_file_editor.rb', line 19 def set(items) items.each do |k, v| @batch.set(k => v) WindowsEnv.user.set(k => v) if global end end |
#switch_gem_home_to(gem_home) ⇒ Object
41 42 43 44 45 |
# File 'lib/pik/commands/batch_file_editor.rb', line 41 def switch_gem_home_to(gem_home) gem_home = Pathname(gem_home).to_windows rescue nil @batch.set('GEM_PATH' => gem_home ) @batch.set('GEM_HOME' => gem_home ) end |
#switch_path_to(other) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pik/commands/batch_file_editor.rb', line 26 def switch_path_to(other) current = Which::Ruby.find new_path = SearchPath.new(ENV['PATH']) new_path.replace_or_add(current, other[:path]) # if there is currently a GEM_HOME, remove it's bin dir from the path new_path.remove(Pathname.new(ENV['GEM_HOME']) + 'bin') if ENV['GEM_HOME'] # if the new version has a GEM_HOME, add it's bin dir to the path new_path.add(Pathname.new(other[:gem_home]) + 'bin') if other[:gem_home] @batch.set('PATH' => new_path.join ) end |