Class: Hugo::Database

Inherits:
Object
  • Object
show all
Includes:
Mixin::ParamsValidate, Singleton
Defined in:
lib/hugo/database.rb

Overview

Lauch Database Servers

Constant Summary collapse

DEFAULT_SERVER =
"DEFAULT"
DEFAULT_SIZE =
5
DEFAULT_ZONE =
'us-east-1c'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::ParamsValidate

#set_or_return, #validate

Constructor Details

#initializeDatabase

initialize defaults



15
16
17
18
19
20
# File 'lib/hugo/database.rb', line 15

def initialize
  size DEFAULT_SIZE
  zone DEFAULT_ZONE
  server DEFAULT_SERVER
  db_security_group "default"
end

Instance Attribute Details

#rdsObject

Returns the value of attribute rds.



12
13
14
# File 'lib/hugo/database.rb', line 12

def rds
  @rds
end

Instance Method Details

#aws_access_key_id(arg = nil) ⇒ Object

Aws Access Key for EC2 Deployment



119
120
121
# File 'lib/hugo/database.rb', line 119

def aws_access_key_id(arg=nil)
  set_or_return(:aws_access_key_id, arg, :kind_of => [String]) 
end

#aws_secret_access_key(arg = nil) ⇒ Object

Aws Access Secret Key for EC2 Deployment



124
125
126
# File 'lib/hugo/database.rb', line 124

def aws_secret_access_key(arg=nil)
  set_or_return(:aws_secret_access_key, arg, :kind_of => [String]) 
end

#clearObject

clear attributes of database object



47
48
49
50
51
52
53
54
# File 'lib/hugo/database.rb', line 47

def clear
  @user = nil
  @password = nil
  @server = nil
  @aws_access_key_id = nil
  @aws_secret_access_key = nil
  
end

#db_security_group(arg = nil) ⇒ Object



114
115
116
# File 'lib/hugo/database.rb', line 114

def db_security_group(arg=nil)
  set_or_return(:db_security_group, arg, :kind_of => [String])     
end

#deployObject

deploy using AWS RDS

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hugo/database.rb', line 23

def deploy
  raise ArgumentError, "database.name Required" unless name
  raise ArgumentError, "database.server Required" unless server
  raise ArgumentError, "database.user Required" unless user
  raise ArgumentError, "database.password Required" unless password
  raise ArgumentError, "database.aws_access_key_id Required" unless aws_access_key_id
  raise ArgumentError, "database.aws_secret_access_key Required" unless aws_secret_access_key
  
  
  @rds = Hugo::Aws::Rds.find_or_create( :name => name,
                            :server => server,
                            :user => user,
                            :password => password,
                            :size => size,
                            :zone => zone,
                            :db_security_group => db_security_group,
                            :aws_access_key_id => aws_access_key_id,
                            :aws_secret_access_key => aws_secret_access_key
                            
                             )
  self
end

#helpObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hugo/database.rb', line 56

def help
  
  x = <<HELP
Welcome to Hugo::Database
-------------------------

Required Methods:
-------------------------
name - Name of Database
server - Name of Server
user - A Valid User of RDS Server
password - A Valid Password of RDS Server    

Optional Methods:
-------------------------
size - Storage Size of you db server
zone - Zone of the AWS:RDS

HELP
  puts x
  x
end

#infoObject



79
80
81
82
83
84
85
86
87
# File 'lib/hugo/database.rb', line 79

def info
  { 
    :uri => @rds.uri, 
    :name => @rds.db,
    :user => @rds.user, 
    :password => @rds.password 
    } 
  
end

#name(arg = nil) ⇒ Object



90
91
92
# File 'lib/hugo/database.rb', line 90

def name(arg=nil)
  set_or_return(:name, arg, :kind_of => [String])     
end

#password(arg = nil) ⇒ Object



102
103
104
# File 'lib/hugo/database.rb', line 102

def password(arg=nil)
  set_or_return(:password, arg, :kind_of => [String])     
end

#server(arg = nil) ⇒ Object



94
95
96
# File 'lib/hugo/database.rb', line 94

def server(arg=nil)
  set_or_return(:server, arg, :kind_of => [String])     
end

#size(arg = nil) ⇒ Object



106
107
108
# File 'lib/hugo/database.rb', line 106

def size(arg=nil)
  set_or_return(:size, arg, :kind_of => [Integer])     
end

#user(arg = nil) ⇒ Object



98
99
100
# File 'lib/hugo/database.rb', line 98

def user(arg=nil)
  set_or_return(:user, arg, :kind_of => [String])     
end

#zone(arg = nil) ⇒ Object



110
111
112
# File 'lib/hugo/database.rb', line 110

def zone(arg=nil)
  set_or_return(:zone, arg, :kind_of => [String])     
end