Module: Exodb

Defined in:
lib/exodb/exception.rb,
lib/exodb.rb,
lib/exodb/utils.rb,
lib/exodb/rositza.rb,
lib/exodb/version.rb,
lib/exodb/usermanage.rb,
lib/exodb/dbconnection.rb,
lib/exodb/rositza/load.rb,
lib/exodb/datamodel/region.rb,
lib/exodb/datamodel/source.rb,
lib/exodb/utils/upload_var.rb,
lib/exodb/datamodel/variant.rb,
lib/exodb/utils/ensemblrest.rb,
lib/exodb/datamodel/reference.rb,
lib/exodb/datamodel/xrefsfield.rb,
lib/exodb/utils/upload_generef.rb,
lib/exodb/datamodel/locationfield.rb

Overview

raise “Please, use ruby 1.9.0 or later.” if RUBY_VERSION < “1.9.0”

Defined Under Namespace

Modules: Ensembl, GenomeLocationField, Utils, XrefsField Classes: Aa, CNV, Cell, Change, CreateUserError, Dataset, Gene, Generef, Indel, InvalidResponse, Isoform, Lossgain, Normal, Occurrent, Offexon, Onexon, Reference, Region, SNV, Source, Splice, Tumor, Utr, Variant, Variantref

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.connect(connectionstr = {}) ⇒ Object

Parameters:

  • Connection (Hash, String)

    string or a Hash in format { database: ‘exodus’, hosts: [‘localhost:27017’], username: ‘xxx’, options: {}}



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/exodb/dbconnection.rb', line 30

def connect(connectionstr = {})
	
	settings = { database: 'exodus', hosts: ['localhost:27017'], options: {}}
	
	if connectionstr.is_a?(Hash)
		connectionstr.each_pair {|k, v| settings[k.to_sym] = k.to_sym == :hosts ? [v].flatten : v}
	elsif connectionstr.is_a?(String)
		split1 = connectionstr.split('@')
		settings[:username] = split1[0] if split1.length > 1
		split2 = split1[-1].split('/')
		settings[:database] = split2[1] if split2.length > 1
		settings[:hosts] = [split2[0]].flatten
	end
	
	password = ask("Password:  ") { |q| q.echo = "*" } if settings[:username] && !settings[:password]
	
	Mongoid::Sessions.disconnect
	Mongoid::Sessions.clear
	Mongoid.load_configuration({"sessions"=>{"default"=> password ? settings.merge({password: password}) : settings}})
	
	return "#EXODB:INFO Connection with #{settings}" if Pry.current
end

.create_admin(username, database) ⇒ Object

To create an admin user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



59
60
61
62
63
# File 'lib/exodb/usermanage.rb', line 59

def create_admin(username, database)
	
	create_user(username, database, "readWrite", "dbAdmin", "userAdmin")
	
end

.create_rouser(username) ⇒ Object

To create a read-only user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



78
79
80
81
82
# File 'lib/exodb/usermanage.rb', line 78

def create_rouser(username)
	
	create_user(username, Mongoid.session(:default).options[:database], "read")
	
end

.create_rwuser(username) ⇒ Object

To create a rw user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created



69
70
71
72
73
# File 'lib/exodb/usermanage.rb', line 69

def create_rwuser(username)
	
	create_user(username, Mongoid.session(:default).options[:database], "readWrite")
	
end

.create_user(username, database, *roles) ⇒ Object

General command for creating a user

Parameters:

  • user (String)

    name to be created

  • database (String)

    that user created

  • roles (Array)

    to be assigned to the user



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/exodb/usermanage.rb', line 22

def create_user(username, database, *roles)
	
	if database != 'admin'
		
		password = nil
		confirmed = nil
		
		while !password || password != confirmed
			password = ask("New password:  ") { |q| q.echo = "*" }
			confirmed = ask("Confirm password:  ") { |q| q.echo = "*" }
			
			puts "Password not match!\n" if password != confirmed
			
		end
		
		if database
			Mongoid.session(:default).with(database: database).command(
				createUser: username,
				pwd: password,
				roles: roles.flatten
			)
		else
			Mongoid.session(:default).command(
				createUser: username,
				pwd: password,
				roles: roles.flatten
			)
		end
	else
		raise CreateUserError, 'Cannot create user on admin database'
	end
end

.current_databaseString

Return the current database name

Returns:

  • (String)

    the database name



79
80
81
# File 'lib/exodb/dbconnection.rb', line 79

def current_database
	self.session.options[:database]
end

.sessionString

Return the session setting

Returns:

  • (String)

    the session setting



72
73
74
# File 'lib/exodb/dbconnection.rb', line 72

def session
	Mongoid.session(:default)
end

.sessionload!(sessionfile = nil) ⇒ Object

load session file

Parameters:

  • path (String)

    to session file



19
20
21
22
23
24
25
# File 'lib/exodb/dbconnection.rb', line 19

def sessionload!(sessionfile = nil)
		if sessionfile && File.exist?(sessionfile)
			Mongoid.load!(sessionfile, :production)
		else
			Mongoid.load!("#{Dir.pwd}/session.yml", :production) if File.exist?("#{Dir.pwd}/session.yml")
		end
end