Class: GettextI18nRails::ModelAttributesFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/gettext_i18n_rails/model_attributes_finder.rb

Instance Method Summary collapse

Instance Method Details

#find(options) ⇒ Object

options:

:ignore_tables => ['cars',/_settings$/,...]
:ignore_columns => ['id',/_id$/,...]

current connection —> href="'model_name','type'">cars’=>,…



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gettext_i18n_rails/model_attributes_finder.rb', line 35

def find(options)
  found = ActiveSupport::OrderedHash.new([])

  models.each do |model|
    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) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/gettext_i18n_rails/model_attributes_finder.rb', line 59

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

#modelsObject



50
51
52
53
54
55
56
57
# File 'lib/gettext_i18n_rails/model_attributes_finder.rb', line 50

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