class RuboCop::Rails::SchemaLoader::Schema
Represent db/schema.rb
Attributes
add_indicies[R]
tables[R]
Public Class Methods
new(ast)
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 10 def initialize(ast) @tables = [] @add_indicies = [] build!(ast) end
Public Instance Methods
add_indicies_by(table_name:)
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 23 def add_indicies_by(table_name:) add_indicies.select do |add_index| add_index.table_name == table_name end end
table_by(name:)
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 17 def table_by(name:) tables.find do |table| table.name == name end end
Private Instance Methods
build!(ast)
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 31 def build!(ast) raise "Unexpected type: #{ast.type}" unless ast.block_type? each_table(ast) do |table_def| @tables << Table.new(table_def) end # Compatibility for Rails 4.2. each_add_index(ast) do |add_index_def| @add_indicies << AddIndex.new(add_index_def) end end
each_add_index(ast) { |node| ... }
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 57 def each_add_index(ast) ast.body.children.each do |node| next if !node&.send_type? || !node.method?(:add_index) yield(node) end end
each_table(ast) { |node| ... }
click to toggle source
# File lib/rubocop/rails/schema_loader/schema.rb, line 44 def each_table(ast) case ast.body.type when :begin ast.body.children.each do |node| next unless node.block_type? && node.method?(:create_table) yield(node) end else yield ast.body end end