Module: AldyDebugKitSqlite3

Defined in:
lib/aldy_debug_kit_sqlite3.rb,
lib/aldy_debug_kit_sqlite3/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.getTablesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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"].include?(model_name)
      column_names = model_name.constantize.column_names
      rows = model_name.constantize.all
      model = {"table_name" => table_name, "model_name" => model_name, "column_names" => column_names, "rows" => rows}
      models.push(model)
    end
  end
  return models
end

.greetObject

Your code goes here…



5
6
7
# File 'lib/aldy_debug_kit_sqlite3.rb', line 5

def self.greet
  'Hey! I am Tsukasa Maruyama! Call me Aldy!'
end

.setUpObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/aldy_debug_kit_sqlite3.rb', line 24

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/Hedden
        </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