Class: Retriever

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/retriever.rb

Overview

Copies files from the project directories in FIG_HOME to the user’s working directory. It keeps track of which files have already been copied, and which package/versions they came from, and deletes files as necessary to ensure that we never have files from two different versions of the same package in the user’s working directory.

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ Retriever

Returns a new instance of Retriever.



12
13
14
15
16
17
18
19
20
21
# File 'lib/fig/retriever.rb', line 12

def initialize(base_dir)
  @base_dir = base_dir
  @configs = {}
  @fig_dir = File.join(@base_dir, '.fig')

  file = File.join(@fig_dir, 'retrieve')
  if File.exist?(file)
    load(file)
  end
end

Instance Method Details

#retrieve(source, relpath) ⇒ Object



43
44
45
# File 'lib/fig/retriever.rb', line 43

def retrieve(source, relpath)
  copy(source, relpath)
end

#saveObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/fig/retriever.rb', line 47

def save
  FileUtils.mkdir_p(@fig_dir)
  File.open(File.join(@fig_dir, 'retrieve'), 'w') do |f|
    @configs.each do |name,config|
      config.files.each do |target|
        f << target << '=' << config.name << '/' << config.version << "\n"
      end
    end
  end
end

#with_package_config(name, version) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fig/retriever.rb', line 23

def with_package_config(name, version)
  if name and version
    @config = @configs[name]
    if @config && @config.version != version
      @config.files.each do |relpath|
        Fig::Logging.info "- [#{@config.name}/#{@config.version}] #{relpath}"
        FileUtils.rm_f(File.join(@base_dir, relpath))
      end
      @config = nil
    end
    if not @config
      @config = new_package_config(name, version)
      @configs[name] = @config
    end
  else
    @config = nil
  end
  yield
end