class GettextI18nRails::ModelAttributesFinder

Public Instance Methods

find(options) click to toggle source

options:

:ignore_tables => ['cars',%r_settings$/,...]
:ignore_columns => ['id',%r_id$/,...]

current connection ---> {'cars'=>,...}

# File lib/gettext_i18n_rails/model_attributes_finder.rb, line 35
def find(options)
  found = ActiveSupport::OrderedHash.new([])

  models.each do |model|
    next if model.abstract_class
    table_name = model.table_name
    next if ignored?(table_name,options[:ignore_tables])
    model.columns.each do |column|
      found[model] += [column.name] unless ignored?(column.name,options[:ignore_columns])
    end
    found[model].sort!
  end

  found
end
ignored?(name,patterns) click to toggle source
# File lib/gettext_i18n_rails/model_attributes_finder.rb, line 60
def ignored?(name,patterns)
  return false unless patterns
  patterns.detect{|p|p.to_s==name.to_s or (p.is_a?(Regexp) and name=~p)}
end
models() click to toggle source
# File lib/gettext_i18n_rails/model_attributes_finder.rb, line 51
def models
  if Rails::VERSION::MAJOR > 2
    Rails.application.eager_load! # make sure that all models are loaded so that direct_descendants works
    ::ActiveRecord::Base.direct_descendants
  else
    ::ActiveRecord::Base.connection.tables.map {|t| table_name_to_namespaced_model(t) }
  end.compact.sort {|c1, c2| c1.name <=> c2.name}
end