class NillyVanilly::Inspect

Inspect the database schema, in a quest to find columns suitable for nillification.

Public Class Methods

new() click to toggle source
# File lib/nilly_vanilly/inspect.rb, line 4
def initialize
  @results = []
end
print() click to toggle source

Print an inspection report to stdout.

Public Instance Methods

results() click to toggle source

A nested array with one row for each column suitable for nillification.

# File lib/nilly_vanilly/inspect.rb, line 9
def results
  ActiveRecord::Base.connection.tables.each do |table|
    model = table.classify.constantize rescue next

    model.columns.each do |column|
      present = model.respond_to?(:nillify_attributes) && model.nillify_attributes.include?(column.name.to_sym)

      @results << [present, model.name, column.name] if include_column(column)
    end
  end

  @results
end

Private Instance Methods

include_column(column) click to toggle source
# File lib/nilly_vanilly/inspect.rb, line 31
def include_column(column)
  %i(string text).include?(column.type) && column.null && column.default.nil?
end