Class: DbBrowser::Server

Inherits:
Sinatra::Base
  • Object
show all
Includes:
TextUtils::HypertextHelper
Defined in:
lib/dbbrowser/server.rb

Constant Summary collapse

PUBLIC_FOLDER =
"#{DbBrowser.root}/lib/dbbrowser/public"
VIEWS_FOLDER =
"#{DbBrowser.root}/lib/dbbrowser/views"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



12
13
14
# File 'lib/dbbrowser/server.rb', line 12

def self.banner
  "dbbrowser #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] on Sinatra/#{Sinatra::VERSION} (#{ENV['RACK_ENV']})"
end

Instance Method Details

#db_path(key) ⇒ Object



39
40
41
# File 'lib/dbbrowser/server.rb', line 39

def db_path( key )
  "#{path_prefix}/db/#{key}"
end

#h(text) ⇒ Object



51
52
53
# File 'lib/dbbrowser/server.rb', line 51

def h( text )
  Rack::Utils.escape_html(text)
end

#path_prefixObject



35
36
37
# File 'lib/dbbrowser/server.rb', line 35

def path_prefix
  request.script_name   # request.env['SCRIPT_NAME']
end

#render_spec_for(key, opts = {}) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/dbbrowser/server.rb', line 55

def render_spec_for( key, opts={} )
  # render connection spec(ification) aka configuration
  spec = ActiveRecord::Base.configurations[ key ]
  erb( 'shared/_spec'.to_sym,
       layout: false,
       locals: { spec: spec })
end

#render_table_def(table, opts = {}) ⇒ Object



63
64
65
66
67
# File 'lib/dbbrowser/server.rb', line 63

def render_table_def( table, opts={} )
  erb( 'shared/_table_def'.to_sym,
       layout: false,
       locals: { table: table } )
end

#render_tables(tables, opts = {}) ⇒ Object



69
70
71
72
73
# File 'lib/dbbrowser/server.rb', line 69

def render_tables( tables, opts={} )
  erb( 'shared/_tables'.to_sym,
       layout: false,
       locals: { tables: tables } )
end

#render_tables_for(key, opts = {}) ⇒ Object



75
76
77
78
79
80
# File 'lib/dbbrowser/server.rb', line 75

def render_tables_for( key, opts={} )
  con = settings.man.connection_for( key )
  erb( 'shared/_tables'.to_sym,
       layout: false,
       locals: { tables: con.tables } )
end

#root_pathObject



47
48
49
# File 'lib/dbbrowser/server.rb', line 47

def root_path
  "#{path_prefix}/"
end

#table_path(table) ⇒ Object



43
44
45
# File 'lib/dbbrowser/server.rb', line 43

def table_path( table )
  "#{path_prefix}/db/#{table.connection.key}/#{table.name.downcase}"
end