Module: Golem::DB

Defined in:
lib/golem/db.rb

Overview

Database handling. See Pg and Static.

A db should respond to 4 methods: users, repositories, ssh_keys, setup. The first 3 should take a single hash argument (options) and return an array/hash of results, setup takes no arguments (it may use a block). These options should be supported:

  • :fields: list of fields the results should include,

  • :return: type of return value, if is :array then results should be an array, hash (attribute name => value pairs) otherwise,

  • any other key: should be interpreted as conditions (e.g. :user => “name” should return objects whose user attribute is name).

Defined Under Namespace

Classes: Pg, Static

Class Method Summary collapse

Class Method Details

.dbPg, Static

Proxy for the used db.

Returns:

  • (Pg, Static)

    the db currently used.



15
16
17
18
19
20
21
# File 'lib/golem/db.rb', line 15

def self.db
	@db ||= case Golem::Config.db
 when /\Apostgres:\/\// then Pg.new(Golem::Config.db)
 when "static" then Static.new
 else abort "Unknown DB (#{Golem::Config.db.to_s})."
 end
end

.repositories(opts = {}) ⇒ Array, Hash

Forwards to proxy’s repositories.

Returns:

  • (Array, Hash)

    results.



31
32
33
# File 'lib/golem/db.rb', line 31

def self.repositories(opts = {})
	db.repositories(opts)
end

.setup(&block) ⇒ Object

Forwards to proxy’s setup.

Returns:

  • depends on proxy.



43
44
45
# File 'lib/golem/db.rb', line 43

def self.setup(&block)
	db.setup(&block)
end

.ssh_keys(opts = {}) ⇒ Array, Hash

Forwards to proxy’s ssh_keys.

Returns:

  • (Array, Hash)

    results.



37
38
39
# File 'lib/golem/db.rb', line 37

def self.ssh_keys(opts = {})
	db.ssh_keys(opts)
end

.users(opts = {}) ⇒ Array, Hash

Forwards to proxy’s users.

Returns:

  • (Array, Hash)

    results.



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

def self.users(opts = {})
	db.users(opts)
end