module AldyDebugKitSqlite3

Constants

VERSION

Public Class Methods

getTables() click to toggle source
# File lib/aldy_debug_kit_sqlite3.rb, line 9
def self.getTables
  table_names = ActiveRecord::Base.connection.tables
  models = []
  table_names.each do |table_name|
    model_name = table_name.classify
    if !["ArInternalMetadatum", "SchemaMigration"].include?(model_name)
      begin
        model_object =  model_name.constantize
      rescue => exception
        next
      end
      column_names = model_object.column_names
      rows = model_object.all
      model = {"table_name": table_name, "model_name": model_name, "column_names": column_names, "rows": rows}
      models.push(model)
    end
  end
  return models
end
greet() click to toggle source

Your code goes here…

# File lib/aldy_debug_kit_sqlite3.rb, line 5
def self.greet
  'Hey! I am Tsukasa Maruyama! Call me Aldy!'
end
setUp() click to toggle source
# File lib/aldy_debug_kit_sqlite3.rb, line 29
def self.setUp

  template = %Q{
      <!DOCTYPE html>
      <html>
      <head>
      <meta charset="utf-8" />
      <title>Show Tables</title>
      <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

      <style>
      body {
        margin: 3% 5%
      }
      </style>
      </head>
      <body >

      <% @models.each do |model| %>
      <div class="page-header">
        <h1>
          <%= model[:table_name] %>
          <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample_<%= model[:model_name] %>" role="button" aria-expanded="false" aria-controls="collapseExample">
          Show/Hidden
        </a>
        </h1>
      </div>
      <div class="collapse" id="collapseExample_<%= model[:model_name] %>">
      <table class="table table-bordered table-striped table-sm">
        <thead class="thead-dark">
          <tr>
          <% model[:column_names].each do |column_name|  %>
            <th scope="col"><%= column_name %></th>
          <% end %>
          </tr>
        </thead>
        <tbody>
        <% model[:rows].each do |row|  %>
          <tr>
          <% model[:column_names].each do |column_name|  %>
            <td><%= row[column_name] %></td>
          <% end %>
          </tr>
        <% end %>
        </tbody>
      </table>
      </div>
      <% end %>
      </body>
      </html>
  }

  File.open("views/aldy_show_sqlite3_tables.erb","w") do |text|
      template.each_line do |line|
        text.puts(line)
      end
  end

  action_text = %Q{
  get '/models' do
    @models = AldyDebugKitSqlite3.getTables
    erb :aldy_show_sqlite3_tables
  end
  }

  File.open("show_table_action.rb","w") do |text|
      action_text.each_line do |line|
        text.puts(line)
      end
  end

  puts "Setup finished!"
end