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
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 274 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
286 287 288 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 286 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, …
292 293 294 295 296 297 298 299 300 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 292 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
303 304 305 |
# File 'lib/updateable_views_inheritance/postgresql_adapter.rb', line 303 def model_filenames Dir.chdir("#{Rails.root}/app/models"){ Dir["**/*.rb"] } end |