Module: Msip::TareasrakeHelper

Defined in:
app/helpers/msip/tareasrake_helper.rb

Class Method Summary collapse

Class Method Details

.asegura_varambiente_bdObject

Asegura que están establecidas variables de ambiente con información para conexión a la base de datos: BD_SERVIDOR, BD_USUARIO, BD_CLAVE, BD_NOMBRE



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/msip/tareasrake_helper.rb', line 8

def asegura_varambiente_bd
  # Toma ideas de https://github.com/opdemand/puppet-modules/blob/master/rails/files/databases.rake
  abcs = ActiveRecord::Base.configurations
  confbd = abcs.configurations.select { |c| c.env_name == Rails.env }.first

  unless ENV["BD_SERVIDOR"]
    ENV["BD_SERVIDOR"] = confbd.configuration_hash[:host] ||
      "/var/www/var/run/postgresql"
  end
  unless ENV["BD_USUARIO"]
    ENV["BD_USUARIO"] = confbd.configuration_hash[:username] ||
      "msipdes"
  end
  unless ENV["BD_CLAVE"]
    ENV["BD_CLAVE"] = confbd.configuration_hash[:password] ||
      "CambiarPorClave"
  end
  ENV["BD_NOMBRE"] = if Rails.env.production?
    ENV.fetch(
      "BD_PRO", confbd.configuration_hash[:database] || "bdproduccion"
    )
  elsif Rails.env.development?
    ENV.fetch(
      "BD_DES", confbd.configuration_hash[:database] || "bddesarrollo"
    )
  else
    ENV.fetch(
      "BD_PRUEBA", confbd.configuration_hash[:database] || "bdprueba"
    )
  end
end

.nombre_volcado(ruta_volcados, rapido = false) ⇒ Object

Nombre de archivo con copia de volcado de base de hoy



42
43
44
45
46
47
48
# File 'app/helpers/msip/tareasrake_helper.rb', line 42

def nombre_volcado(ruta_volcados, rapido = false)
  dia = Time.zone.now.strftime("%d")
  asegura_varambiente_bd
  crapido = rapido ? "-rapido" : ""
  ruta_volcados + "/" + ENV.fetch("BD_NOMBRE") +
    "-" + dia + crapido + ".sql"
end

.which(cmd) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'app/helpers/msip/tareasrake_helper.rb', line 52

def which(cmd)
  exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{cmd}#{ext}")
      return exe if File.executable?(exe) && !File.directory?(exe)
    end
  end
  nil
end