class Fixman::Controller

Attributes

repos[R]

Public Class Methods

new(repos = []) click to toggle source
# File lib/fixman/controller.rb, line 9
def initialize(repos = [])
  @repos = repos
end
open(conf) { |controller| ... } click to toggle source

Controller for the command line interface.

# File lib/fixman/controller.rb, line 67
def open(conf)
  original_ledger = ""

  controller =
  begin
    original_ledger = YAML.load(IO.read conf.fixture_ledger)
    original_ledger.map! { |entry| YAML.load entry } 

    repos = []
    original_ledger.each do |repo_params|
      repos << Repository.new(repo_params,
                              conf.fixtures_base,
                              conf.extra_repo_info)
    end

    Controller.new repos
  rescue Errno::ENOENT
    Controller.new
  end

  result = yield controller

  write_ledger controller.repos, original_ledger, conf.fixture_ledger

  result
rescue Git::GitExecuteError => error
  puts error.message
  exit 1
end

Private Class Methods

write_ledger(repos, original_ledger, fixture_ledger) click to toggle source
# File lib/fixman/controller.rb, line 99
def write_ledger(repos, original_ledger, fixture_ledger)
  new_ledger = YAML.dump repos.map(&:to_yaml)
  if new_ledger != original_ledger
    IO.write fixture_ledger, new_ledger
  end
end

Public Instance Methods

add(input, fixtures_base, extra_repo_info) click to toggle source

Add a new repository to the collection.

# File lib/fixman/controller.rb, line 14
def add(input, fixtures_base, extra_repo_info)
  repo = Repository.new input, fixtures_base, extra_repo_info

  @repos << repo
end
delete(canonical_name) click to toggle source

Remove repository from the fixtures list.

# File lib/fixman/controller.rb, line 21
def delete(canonical_name)
  repo = find canonical_name

  if repo
    @repos.delete repo
    repo.destroy
  else
    fail ArgumentError
  end
end
fetch(groups) click to toggle source

Download repositories belonging to the at least one of the given groups.

# File lib/fixman/controller.rb, line 33
def fetch(groups)
  repos = find_by_groups(groups).reject { |repo| repo.fetched? }
  repos.each do |repo|
    begin
      repo.fetch
    rescue Git::GitExecuteError => error
      STDERR.puts "Warning: Repository #{repo.canonical_name} could not be fetched."
      STDERR.puts error.message
    end
  end
end
update(canonical_name, sha = nil) click to toggle source
# File lib/fixman/controller.rb, line 45
def update(canonical_name, sha = nil)
  repo = find canonical_name
  fail ArgumentError unless repo

  repo.sha = sha || repo.retrieve_head_sha
end
upgrade(groups) click to toggle source
# File lib/fixman/controller.rb, line 52
def upgrade(groups)
  repos = find_by_groups(groups) 
  repos.each do |repo| 
    begin
      repo.upgrade
    rescue Git::GitExecuteError => error
      STDERR.puts "Warning: Repisotiry #{repo.canonical_name} could not be \"
        upgraded."
      STDERR.puts error.message
    end
  end
end

Private Instance Methods

find(canonical_name) click to toggle source
# File lib/fixman/controller.rb, line 117
def find(canonical_name)
  @repos.find { |repo| canonical_name == repo.canonical_name }
end
find_by_groups(groups) click to toggle source
# File lib/fixman/controller.rb, line 109
def find_by_groups(groups)
  if groups.empty?
    @repos
  else
    @repos.select { |repo| !(repo.groups & groups).empty? }
  end
end