Module: Dorothy::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/dorothy2/do-utils.rb

Instance Method Summary collapse

Instance Method Details

#exists?(file) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/dorothy2/do-utils.rb', line 15

def exists?(file)
  File.exist?(file)
end

#init_db(force = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dorothy2/do-utils.rb', line 19

def init_db(force=false)
  LOGGER.warn "DB", "The database is going to be initialized, all the data present will be lost. Continue?(write yes)"
  answ = "yes"
  answ = gets.chop unless force

  if answ == "yes"
    begin
      #ugly, I know, but couldn't find a better and easier way..
      raise 'An error occurred' unless system "psql -h #{DoroSettings.dorothive[:dbhost]} -U #{DoroSettings.dorothive[:dbuser]} -f #{DoroSettings.dorothive[:ddl]}"
      LOGGER.info "DB", "Database correctly initialized."
    rescue => e
      LOGGER.error "DB", $!
      LOGGER.debug "DB", e.inspect
    end
  else
    LOGGER.error "DB", "Database untouched, quitting."
  end
end

#write(file, string) ⇒ Object



11
12
13
# File 'lib/dorothy2/do-utils.rb', line 11

def write(file, string)
  File.open(file , 'w') {|f| f.write(string) }
end