Class: Ripe::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/ripe/repo.rb

Overview

This class represents a ripe session. It is similar to the concept of a git repository and is the starting point of the package. It instantiates:

  • a database that contains all worker metadata; and

  • a controller that communicates with both the database and the compute cluster interface.

Constant Summary collapse

REPOSITORY_PATH =
'.ripe'
DATABASE_PATH =
"#{REPOSITORY_PATH}/meta.db"
WORKERS_PATH =
"#{REPOSITORY_PATH}/workers"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepo

Initialize a repository.



32
33
34
35
# File 'lib/ripe/repo.rb', line 32

def initialize
  @has_repository = File.exists? DATABASE_PATH
  @controller     = WorkerController.new
end

Instance Attribute Details

#controllerWorkerController (readonly)

a controller that communicates with both the database and the computer cluster interface.

Returns:



21
22
23
# File 'lib/ripe/repo.rb', line 21

def controller
  @controller
end

Instance Method Details

#attachObject

Attach to an existing database.



49
50
51
52
53
54
# File 'lib/ripe/repo.rb', line 49

def attach
  ActiveRecord::Base.establish_connection({
    adapter:  'sqlite3',
    database: DATABASE_PATH,
  })
end

#attach_or_createObject

Attach to an existing database, and creates one if a database cannot be found.



60
61
62
# File 'lib/ripe/repo.rb', line 60

def attach_or_create
  @has_repository ? attach : create
end

#createObject

Create a database.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ripe/repo.rb', line 67

def create
  FileUtils.mkdir_p(REPOSITORY_PATH)
  @has_repository = true

  begin
    attach

    # Create the tables
    DB::WorkerMigration.up
    DB::TaskMigration.up

    # Set the database's permissions to the user's umask
    FileUtils.chmod(0666 - File.umask(), DATABASE_PATH)
  rescue
    destroy
  end
end

#destroyObject

Destroy the ripe repository, including the database and the worker output.



89
90
91
92
# File 'lib/ripe/repo.rb', line 89

def destroy
  FileUtils.rm(DATABASE_PATH) if File.exists? DATABASE_PATH
  FileUtils.rm(WORKERS_PATH)  if Dir.exists?  WORKERS_PATH
end

#has_repository?Boolean

Return whether the ripe repository exists.

Returns:

  • (Boolean)

    whether the repository exists



42
43
44
# File 'lib/ripe/repo.rb', line 42

def has_repository?
  @has_repository
end