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) unless File.symlink?@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



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

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) ⇒ Object



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

def replace_references(in_file)
  GalaxyStager.replace_references(in_file, @original_path, replacement)
end

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



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

def restore_references(in_file, options = {})
  path = options[:base_only] ? @staged_path.gsub(/#{@extension}/,"") : @staged_path
  GalaxyStager.replace_references(in_file, path, @original_path)
end