Class: Lazer::SchemaController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lazer/schema_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate!

Instance Method Details

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/lazer/schema_controller.rb', line 6

def show
  require_page!; return if performed?

  Rails.application.eager_load!
  models = ActiveRecord::Base.descendants

  result = {}

  page = params[:page].to_i
  models_per_page = 30
  offset = (page - 1) * models_per_page

  models = models[offset, models_per_page] || []
  result[:models] = models.map do |model|
    parse_model(model)
  end

  # not necessarily needed, can get tables directly from the db
  # result[:raw_tables] = gather_tables

  result[:count] = models.length
  result[:page] = page
  result[:offset] = offset

  render json: result.to_json
end