Class: ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements::Tutuf::ClassTableReflection
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements::Tutuf::ClassTableReflection
- Defined in:
- lib/updateable_views_inheritance/postgresql_adapter.rb
Class Method Summary collapse
-
.all_db_klasses ⇒ Object
Returns all models’ class objects that are ActiveRecord::Base descendants.
-
.get_klass_for_table(table_name) ⇒ Object
Returns the class object for
table_name
. -
.klass_for_tables ⇒ Object
Returns hash with tables and thier corresponding class.
-
.model_filenames ⇒ Object
Returns filenames for models in the current Rails application.
Class Method Details
.all_db_klasses ⇒ Object
Returns all models’ class objects that are ActiveRecord::Base descendants
264 265 266 267 268 269 270 271 272 273 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 264 def all_db_klasses return @@klasses if defined?(@@klasses) @@klasses = [] # load model classes so that inheritance_column is set correctly where defined model_filenames.collect{|m| load "#{Rails.root}/app/models/#{m}";m.match(%r{([^/]+?)\.rb$})[1].camelize.constantize }.each do |klass| @@klasses << klass if klass < ActiveRecord::Base end @@klasses.uniq end |
.get_klass_for_table(table_name) ⇒ Object
Returns the class object for table_name
276 277 278 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 276 def get_klass_for_table(table_name) klass_for_tables()[table_name.to_s] end |
.klass_for_tables ⇒ Object
Returns hash with tables and thier corresponding class. => ClassName1, …
282 283 284 285 286 287 288 289 290 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 282 def klass_for_tables return @@tables_klasses if defined?(@@tables_klasses) @@tables_klasses = {} all_db_klasses.each do |klass| @@tables_klasses[klass.table_name] = klass if klass.respond_to?(:table_name) end @@tables_klasses end |
.model_filenames ⇒ Object
Returns filenames for models in the current Rails application
293 294 295 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 293 def model_filenames Dir.chdir("#{Rails.root}/app/models"){ Dir["**/*.rb"] } end |