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
251 252 253 254 255 256 257 258 259 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 251 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
262 263 264 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 262 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, …
268 269 270 271 272 273 274 275 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 268 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
278 279 280 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 278 def model_filenames Dir.chdir("#{Rails.root}/app/models"){ Dir["**/*.rb"] } end |