Class: Golem::DB::Static

Inherits:
Object
  • Object
show all
Defined in:
lib/golem/db/static.rb

Overview

Static database for small installations. To use it, write:

Golem.configure do |cfg|
  cfg.db = 'static'
  Golem::DB.setup do |db|
    db.add_user 'test_user'
    db.add_repository 'test_repository', 'test_user'
    db.add_key 'test_user', 'test_key'
  end
end

Instance Method Summary (collapse)

Constructor Details

- (Static) initialize

Create database, initialize users, repositories and ssh_keys to [].



12
13
14
# File 'lib/golem/db/static.rb', line 12

def initialize
	@users, @repositories, @ssh_keys = [], [], []
end

Instance Method Details

- (Array) add_key(user_name, key)

Add key to database.

Parameters:

  • user_name (String)

    username,

  • key (String)

    ssh key (e.g. cat id_rsa.pub).

Returns:

  • (Array)

    list of keys.



57
58
59
60
# File 'lib/golem/db/static.rb', line 57

def add_key(user_name, key)
	abort "Cannot add key, user not found!" unless users(:return => :array).include?(user_name)
	@ssh_keys << {:user_name => user_name, :key => key}
end

- (Array) add_repository(name, user_name)

Add repository to database.

Parameters:

  • name (String)

    repository name,

  • user_name (String)

    username.

Returns:

  • (Array)

    list of repositories.



48
49
50
51
# File 'lib/golem/db/static.rb', line 48

def add_repository(name, user_name)
	abort "Cannot add repository, user not found!" unless users(:return => :array).include?(user_name)
	@repositories << {:name => name, :user_name => user_name}
end

- (Array) add_user(name)

Add user to database.

Parameters:

  • name (String)

    username,

Returns:

  • (Array)

    list of users.



40
41
42
# File 'lib/golem/db/static.rb', line 40

def add_user(name)
	@users << {:name => name}
end

- (Array) repositories(opts = {})

Retrieve repositories.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of repotitories.



26
27
28
# File 'lib/golem/db/static.rb', line 26

def repositories(opts = {})
	opts[:return] == :array ? @repositories.collect {|r| r[:name]} : @repositories
end

- (Object) setup {|_self| ... }

Setup database.

Yields:

  • (_self)

Yield Parameters:



63
64
65
# File 'lib/golem/db/static.rb', line 63

def setup(&block)
	yield self
end

- (Array) ssh_keys(opts = {})

Retrieve ssh keys.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of keys.



33
34
35
# File 'lib/golem/db/static.rb', line 33

def ssh_keys(opts = {})
	opts[:return] == :array ? @ssh_keys.collect {|k| [k[:user_name], k[:key]]} : @ssh_keys
end

- (Array) users(opts = {})

Retrieve users.

Parameters:

  • opts (Hash) (defaults to: {})

    options, see Golem::DB.

Returns:

  • (Array)

    list of users.



19
20
21
# File 'lib/golem/db/static.rb', line 19

def users(opts = {})
	opts[:return] == :array ? @users.collect {|u| u[:name]} : @users
end