Class: RailsDevtools::DatabaseTableSearchForm

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/forms/rails_devtools/database_table_search_form.rb

Constant Summary collapse

DatabaseTable =
Data.define(:table_name, :columns, :indexes)

Instance Method Summary collapse

Constructor Details

#initialize(search: "") ⇒ DatabaseTableSearchForm

Returns a new instance of DatabaseTableSearchForm.



9
10
11
# File 'app/forms/rails_devtools/database_table_search_form.rb', line 9

def initialize(search: "")
  @search = search.downcase
end

Instance Method Details

#resultsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/forms/rails_devtools/database_table_search_form.rb', line 13

def results
  table_names = ActiveRecord::Base.connection.tables - ["schema_migrations", "ar_internal_metadata"]

  tables = table_names.map do |table|
    DatabaseTable.new(
      table_name: table,
      columns: ActiveRecord::Base.connection.columns(table),
      indexes: indexes(table)
    )
  end

  return tables if @search.empty?

  tables.select do |table|
    table.table_name.include?(@search) ||
      table.columns.any? { |column| column.name.include?(@search) }
  end
end