class SiSU_Info_Db::InfoDb

Public Class Methods

new() click to toggle source
# File lib/sisu/se_db.rb, line 61
def initialize
  @@pwd=@pwd=SiSU_Utils::Path.new.base_markup
  @env=SiSU_Env::InfoEnv.new
  pt=Pathname.new(@pwd)
  r=Px[:lng_lst_rgx]
  u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
  @pwd_stub=pt.realpath.to_s[u,1]
  @rc=@@rc ||=SiSU_Env::GetInit.new.sisu_yaml.rc
  @defaults=SiSU_Env::InfoEnv.new.defaults
end

Public Instance Methods

conn_dbi() click to toggle source
# File lib/sisu/se_db.rb, line 131
def conn_dbi
  DBI.connect(psql.dbi,psql.user,psql.db)
end
conn_pg() click to toggle source
# File lib/sisu/se_db.rb, line 134
def conn_pg
  begin
    require 'pg'
  rescue LoadError
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      error('pg NOT FOUND (LoadError)')
  end
  PG::Connection.new(dbname: psql.db, port: psql.port)
end
conn_sqlite3() click to toggle source
# File lib/sisu/se_db.rb, line 161
def conn_sqlite3
  SQLite3::Database.new(sqlite.sqlite3)
end
db() click to toggle source
# File lib/sisu/se_db.rb, line 101
def db #db_name
  "#{Db[:name_prefix]}#{@pwd_stub}"
end
db_discrete(md) click to toggle source
# File lib/sisu/se_db.rb, line 149
def db_discrete(md)
  # "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
end
dbi() click to toggle source
# File lib/sisu/se_db.rb, line 123
def dbi
  PG::Connection.open(:dbname =>  psql.db)
end
dbi_() click to toggle source
# File lib/sisu/se_db.rb, line 126
def dbi_
  (psql.host =~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
  ? "DBI:Pg:database=#{psql.db};host=#{psql.host};port=#{psql.port}"
  : "DBI:Pg:database=#{psql.db};port=#{psql.port}"
end
default() click to toggle source
# File lib/sisu/se_db.rb, line 78
def default
  ((defined? @rc['db']['engine']['default']) \
  && @rc['db']['engine']['default']=~/postgresql|sqlite/) \
  ? @rc['db']['engine']['default']
  : 'sqlite'
end
engine() click to toggle source
# File lib/sisu/se_db.rb, line 77
def engine
  def default
    ((defined? @rc['db']['engine']['default']) \
    && @rc['db']['engine']['default']=~/postgresql|sqlite/) \
    ? @rc['db']['engine']['default']
    : 'sqlite'
  end
  self
end
host() click to toggle source
# File lib/sisu/se_db.rb, line 117
def host
  ((defined? @rc['db']['postgresql']['host']) \
  && @rc['db']['postgresql']['host']=~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
  ? @rc['db']['postgresql']['host']
  : ''
end
password() click to toggle source
# File lib/sisu/se_db.rb, line 111
def password
  ((defined? @rc['db']['postgresql']['password']) \
  && @rc['db']['postgresql']['password']=~/\S+/) \
  ? @rc['db']['postgresql']['password']
  : ''
end
port() click to toggle source
# File lib/sisu/se_db.rb, line 104
def port #PGPORT
  ((defined? @rc['db']['postgresql']['port']) \
  && ( @rc['db']['postgresql']['port'] =~/\d+/ \
  || @rc['db']['postgresql']['port'].is_a?(Fixnum))) \
  ? @rc['db']['postgresql']['port']
  : (@defaults[:postgresql_port])
end
psql() click to toggle source
# File lib/sisu/se_db.rb, line 86
def psql
  def user(opt=nil)
    if opt \
    and opt.selections.str =~/--db-user[=-]["']?(\S+)["']+/
      $1
    elsif opt \
    and opt.selections.str =~/--webserv[=-]webrick/
      @env.user
    else
      ((defined? @rc['db']['postgresql']['user']) \
      && @rc['db']['postgresql']['user']=~/\S+/) \
      ? @rc['db']['postgresql']['user']
      : @env.user
    end
  end
  def db #db_name
    "#{Db[:name_prefix]}#{@pwd_stub}"
  end
  def port #PGPORT
    ((defined? @rc['db']['postgresql']['port']) \
    && ( @rc['db']['postgresql']['port'] =~/\d+/ \
    || @rc['db']['postgresql']['port'].is_a?(Fixnum))) \
    ? @rc['db']['postgresql']['port']
    : (@defaults[:postgresql_port])
  end
  def password
    ((defined? @rc['db']['postgresql']['password']) \
    && @rc['db']['postgresql']['password']=~/\S+/) \
    ? @rc['db']['postgresql']['password']
    : ''
  end
  def host
    ((defined? @rc['db']['postgresql']['host']) \
    && @rc['db']['postgresql']['host']=~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
    ? @rc['db']['postgresql']['host']
    : ''
  end
  def dbi
    PG::Connection.open(:dbname =>  psql.db)
  end
  def dbi_
    (psql.host =~/(?:\S{1,3}\.){3}\S{1,3}|\S+?\.\S+/) \
    ? "DBI:Pg:database=#{psql.db};host=#{psql.host};port=#{psql.port}"
    : "DBI:Pg:database=#{psql.db};port=#{psql.port}"
  end
  def conn_dbi
    DBI.connect(psql.dbi,psql.user,psql.db)
  end
  def conn_pg
    begin
      require 'pg'
    rescue LoadError
      SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
        error('pg NOT FOUND (LoadError)')
    end
    PG::Connection.new(dbname: psql.db, port: psql.port)
  end
 self
end
share_source?() click to toggle source
# File lib/sisu/se_db.rb, line 71
def share_source?
  ((defined? @rc['db']['share_source']) \
  && @rc['db']['share_source']==true) \
  ? @rc['db']['share_source']
  : false
end
sqlite() click to toggle source
# File lib/sisu/se_db.rb, line 145
def sqlite
  def db
    "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
  end
  def db_discrete(md)
    # "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
  end
  def dbi
    "DBI:SQLite3:#{sqlite.db}" #sqlite3 ?
  end
  def sqlite3
    sqlite.db #sqlite3 ?
  end
  def conn_dbi
    DBI.connect(sqlite.dbi)
  end
  def conn_sqlite3
    SQLite3::Database.new(sqlite.sqlite3)
  end
  self
end
sqlite3() click to toggle source
# File lib/sisu/se_db.rb, line 155
def sqlite3
  sqlite.db #sqlite3 ?
end
user(opt=nil) click to toggle source
# File lib/sisu/se_db.rb, line 87
def user(opt=nil)
  if opt \
  and opt.selections.str =~/--db-user[=-]["']?(\S+)["']+/
    $1
  elsif opt \
  and opt.selections.str =~/--webserv[=-]webrick/
    @env.user
  else
    ((defined? @rc['db']['postgresql']['user']) \
    && @rc['db']['postgresql']['user']=~/\S+/) \
    ? @rc['db']['postgresql']['user']
    : @env.user
  end
end