Class: GalaxyStager

Inherits:
Object
  • Object
show all
Defined in:
lib/protk/galaxy_stager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_path, options = {}) ⇒ GalaxyStager

Returns a new instance of GalaxyStager.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/protk/galaxy_stager.rb', line 8

def initialize(original_path, options = {})
  options = { :name => nil, :extension => '', :force_copy => false }.merge(options)
  @extension = options[:extension]
  @original_path = Pathname.new(original_path)
  @wd = Dir.pwd
  @staged_name = options[:name] || @original_path.basename
  @staged_base = File.join(@wd, @staged_name)
  @staged_path = "#{@staged_base}#{@extension}"
  if options[:force_copy]
    FileUtils.copy(@original_path, @staged_path)
  else
    File.symlink(@original_path, @staged_path)
  end
end

Instance Attribute Details

#staged_pathObject

Returns the value of attribute staged_path.



6
7
8
# File 'lib/protk/galaxy_stager.rb', line 6

def staged_path
  @staged_path
end

Class Method Details

.replace_references(in_file, from_path, to_path) ⇒ Object



33
34
35
36
37
# File 'lib/protk/galaxy_stager.rb', line 33

def self.replace_references(in_file, from_path, to_path)
  puts "Replacing #{from_path} with #{to_path} in #{in_file}"
  cmd="ruby -pi -e \"gsub('#{from_path}', '#{to_path}')\" #{in_file}"
  %x[#{cmd}]
end

Instance Method Details

#replace_references(in_file, options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/protk/galaxy_stager.rb', line 23

def replace_references(in_file, options = {})
  options = { :base_only => false }.merge(options)
  replacement = options[:base_only] ? @staged_base : @staged_path
  GalaxyStager.replace_references(in_file, @original_path, replacement)
end

#restore_references(in_file) ⇒ Object



29
30
31
# File 'lib/protk/galaxy_stager.rb', line 29

def restore_references(in_file)
  GalaxyStager.replace_references(in_file, @staged_path, @original_path)
end