Class: Firebrigade::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/firebrigade/cache.rb

Overview

Firebrigade::Cache is a wrapper around Firebrigade::API that caches lookups so you don’t hammer the web server unnecessarily. It handles the most common operations for Tinderbox::GemTinderbox and Tinderbox::Build.

Instance Method Summary collapse

Constructor Details

#initialize(host, username, password) ⇒ Cache

Creates a new Firebrigade::Cache that will connect to host with username and password.



15
16
17
18
19
20
21
22
23
24
# File 'lib/firebrigade/cache.rb', line 15

def initialize(host, username, password)
  @fa = Firebrigade::API.new host, username, password

  @owners = {} # owner => owner_id
  @projects = {} # [project, owner_id] => project_id
  @versions = {} # [version, project_id] => version_id

  @targets = {} # [version, release_date, platform] => target_id
  @builds = {} # [version_id, target_id] => build_id
end

Instance Method Details

#get_build_id(version_id, target_id) ⇒ Object

Retrieves the id for a build matching version_id and target_id.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/firebrigade/cache.rb', line 29

def get_build_id(version_id, target_id)
  build_args = [version_id, target_id]
  return @builds[build_args] if @builds.include? build_args

  begin
    build = @fa.get_build(*build_args)
    @builds[build_args] = build.id
  rescue Firebrigade::API::NotFound
    nil
  end
end

#get_target_id(version = RUBY_VERSION, release_date = RUBY_RELEASE_DATE, platform = RUBY_PLATFORM) ⇒ Object

Retrieves or creates a target matching version, release_date and platform. Returns the target’s id.



45
46
47
48
49
50
51
52
53
# File 'lib/firebrigade/cache.rb', line 45

def get_target_id(version = RUBY_VERSION, release_date = RUBY_RELEASE_DATE,
                  platform = RUBY_PLATFORM)
  target_args = [version, release_date, platform]
  return @targets[target_args] if @targets.include? target_args

  target = @fa.add_target(*target_args)

  @targets[target_args] = target.id
end

#get_version_id(spec) ⇒ Object

Fetches or creates a version (including project and owner) for the Gem::Specification spec and returns the version’s id.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/firebrigade/cache.rb', line 59

def get_version_id(spec)
  owner = spec.rubyforge_project
  project = spec.name
  version = spec.version.to_s

  owner_id = @owners[owner]

  if owner_id.nil? then
    owner_id = @fa.add_owner(owner).id
    @owners[owner] = owner_id
  end

  project_id = @projects[[owner_id, project]]

  if project_id.nil? then
    project_id = @fa.add_project(project, owner_id).id
    @projects[[owner_id, project]] = project_id
  end

  version_id = @versions[[project_id, version]]

  if version_id.nil? then
    version_id = @fa.add_version(version, project_id).id
    @versions[[project_id, version]] = version_id
  end

  version_id
end