Class: Handy::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/handy/util.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Util

Returns a new instance of Util.



5
6
7
# File 'lib/handy/util.rb', line 5

def initialize(*args)
  @username, @password, @database = *args
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



4
5
6
# File 'lib/handy/util.rb', line 4

def database
  @database
end

#passwordObject

Returns the value of attribute password.



4
5
6
# File 'lib/handy/util.rb', line 4

def password
  @password
end

#usernameObject

Returns the value of attribute username.



4
5
6
# File 'lib/handy/util.rb', line 4

def username
  @username
end

Class Method Details

.execute_cmd(cmd) ⇒ Object



29
30
31
32
# File 'lib/handy/util.rb', line 29

def self.execute_cmd(cmd)
  puts "executing: #{cmd}"
  system cmd
end

.pretty_msg(msg) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/handy/util.rb', line 34

def self.pretty_msg(msg)
  puts ''
  puts '*'*100
  puts ('*' << ' '*5 << msg)
  puts '*'*100
  puts ''
end

.retrieve_db_info(env) ⇒ Object



9
10
11
12
# File 'lib/handy/util.rb', line 9

def self.retrieve_db_info(env)
  config = YAML.load_file(Rails.root.join('config', 'database.yml'))
  self.new(config[env]['username'], config[env]['password'], config[env]['database'])
end

Instance Method Details

#mysql_commandObject



14
15
16
17
18
19
20
# File 'lib/handy/util.rb', line 14

def mysql_command
  a = ['mysql']
  a << "-u #{username}"
  a << "-p'#{password}'" unless password.blank?
  a << database
  a.join(' ')
end

#mysqldump_commandObject



22
23
24
25
26
27
# File 'lib/handy/util.rb', line 22

def mysqldump_command
  a = ['mysqldump']
  a << "-u #{username}"
  a << "-p'#{password}'" unless password.blank?
  a.join(' ')
end