Class: SiSU_Info_Db::InfoDb

Inherits:
SiSU_Info_Env::InfoEnv show all
Defined in:
lib/sisu/se_db.rb

Overview

se_info_env.rb

Direct Known Subclasses

SiSU_Db_Op::DbOp, SiSU_Env::InfoDb

Constant Summary collapse

@@rc =
nil

Instance Attribute Summary

Attributes inherited from SiSU_Info_Env::InfoEnv

#base_markup_dir_stub, #env, #etc, #filename, #flv, #fnb, #fnn, #fnt, #home, #hostname, #processing, #processing_git, #rc, #stub_pwd, #stub_src, #sys, #webserv_host_cgi, #webserv_path, #webserv_port_cgi, #www, #yamlrc_dir

Attributes inherited from SiSU_Env_Call::EnvCall

#ad, #fnb, #fnn, #fnt, #fnv, #fnz, #rc

Instance Method Summary collapse

Methods inherited from SiSU_Info_Env::InfoEnv

#ao, #arch, #asciidoc_ocn?, #bin, #build, #cgi, #cgi_sample_search_form_name, #cjk, #cjk_ja, #cjk_ko, #cjk_zh, #composite_file, #concord_max, #console_web_browser, #console_www_browser, #current_document, #defaults, #digest, #digest_conf?, #dir_url, #docbook_viewer, #encoding, #epub, #epub_bld, #epub_cp_images, #epub_viewer, #feed, #feed_home, #fictionbook_viewer, #file_encoding, #font, #git, #html, #html_minitoc?, #html_navigation?, #html_navigation_bar?, #html_quick_ref?, #html_right_pane?, #html_scroll_1, #html_scroll_2, #html_search_form?, #html_seg_1, #html_seg_2, #html_seg_title_banner?, #html_top_band?, #i18n, #image_external, #image_source, #image_source_include, #image_source_include_local, #image_source_include_remote, #image_source_sisu_includes, #images, #images_epub, #images_external, #images_local, #landscape, #lang_filename, #language, #language_default_set, #length, #links_to_manifest?, #listed?, #local, #locale, #localhost, #lout, #main, #make, #man, #manifest?, #manifest_minitoc?, #manpage, #manpage_generator, #manpage_viewer, #markdown_ocn?, #markup_emphasis, #metadata?, #minitoc?, #mono, #ocn?, #odf, #odf_pth, #odf_viewer, #odt, #odt_bld, #odt_ocn?, #omit_list, #orgmode_ocn?, #output, #output_tell, #papersize, #path, #path_rel_links, #paths, #pattern, #pdf, #pdf_viewer, #pdflatex, #php, #plaintext_ocn?, #plaintext_wrap, #po, #portrait, #postgresql, #pot, #processing_base_tmp, #processing_path, #processing_sisupod, #program, #promo?, #pwd, #rbver, #read_source_file, #read_source_file_array, #read_source_file_string, #remote, #rexml, #rmagick, #root, #root_dir, #rst_ocn?, #sample_data, #sample_search_form_title, #sans, #scripts, #search?, #search_action, #search_fixed?, #search_form, #search_form?, #search_form_static, #segsubtoc?, #serif, #share, #sisupod_gen, #sisupod_gen_v2, #sisupod_gen_v3, #sisupod_v2, #sisupod_v3, #sisupod_v4, #sisurc_path, #sitearch, #size, #source_file_path, #source_file_processing_array, #source_file_with_path, #sql, #src_pod, #src_txt, #stub_dir, #stub_dir_orig, #stub_epub, #stub_md_harvest, #stub_pod, #style, #tex, #texi, #texinfo, #texpdf, #texpdf_hyperlinks, #text_editor, #textile_ocn?, #tidy, #tmp_root_dir, #toc?, #tune, #txt, #type, #url, #usr_dir?, #wc, #web_browser, #webrick, #webrick_port, #webserv, #webserv_base, #webserv_base_cgi, #webserv_cgi, #webserv_dir, #webserv_files_from_db, #webserv_host_base, #webserv_image, #webserv_map_pwd, #webserv_stub_ensure, #widget, #widget_static, #www_browser, #xml_docbook_ocn?, #xml_editor, #xml_fictionbook_ocn?, #xml_scaffold_ocn?, #xml_viewer, #yamlrc

Methods inherited from SiSU_Env_Call::EnvCall

#by?, #by_filename?, #by_filetype?, #by_language_code?, #default_language?, #document_language_versions_found, #dump?, #filename, #lang, #mono_multi_lingual?, #multilingual?, #output_dir_structure, #published_manifests?, #redirect?

Constructor Details

#initializeInfoDb

Returns a new instance of InfoDb.



61
62
63
64
65
66
67
68
69
70
# 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

Instance Method Details

#conn_dbiObject



131
132
133
# File 'lib/sisu/se_db.rb', line 131

def conn_dbi
  DBI.connect(psql.dbi,psql.user,psql.db)
end

#conn_pgObject



134
135
136
137
138
139
140
141
142
# 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_sqlite3Object



161
162
163
# File 'lib/sisu/se_db.rb', line 161

def conn_sqlite3
  SQLite3::Database.new(sqlite.sqlite3)
end

#dbObject

db_name



101
102
103
# File 'lib/sisu/se_db.rb', line 101

def db #db_name
  "#{Db[:name_prefix]}#{@pwd_stub}"
end

#db_discrete(md) ⇒ Object



149
150
151
# File 'lib/sisu/se_db.rb', line 149

def db_discrete(md)
  # "#{@env.path.webserv}/#{@pwd_stub}/sisu_sqlite.db"
end

#dbiObject

“#SiSU_Info_Db::InfoDb.@[email protected]@env.path.webserv/#@pwd_stub/sisu_sqlite.db”



152
153
154
# File 'lib/sisu/se_db.rb', line 152

def dbi
  PG::Connection.open(:dbname =>  psql.db)
end

#dbi_Object



126
127
128
129
130
# 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

#defaultObject



78
79
80
81
82
83
# 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

#engineObject



77
78
79
80
81
82
83
84
85
# 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

#hostObject



117
118
119
120
121
122
# 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

#passwordObject



111
112
113
114
115
116
# 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

#portObject

PGPORT



104
105
106
107
108
109
110
# 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

#psqlObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# 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?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
# 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

#sqliteObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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

#sqlite3Object



155
156
157
# File 'lib/sisu/se_db.rb', line 155

def sqlite3
  sqlite.db #sqlite3 ?
end

#user(opt = nil) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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