Module: ModelDiscovery
- Defined in:
- lib/model_discovery.rb,
lib/model_discovery/engine.rb,
lib/model_discovery/version.rb,
lib/model_discovery/discovery.rb
Defined Under Namespace
Classes: Engine
Constant Summary collapse
- VERSION =
"0.3.4"
Class Method Summary collapse
-
.build_table_list(without_habtm = true) ⇒ Object
Create a list of current rails application tables or documents.
Class Method Details
.build_table_list(without_habtm = true) ⇒ Object
Create a list of current rails application tables or documents
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/model_discovery/discovery.rb', line 4 def self.build_table_list(without_habtm = true) # Get all gem by requiring them all_gems = Bundler.require() # Discover all model files in gem files and load them all_gems.each do |gem| if gem.groups.include? Rails.env.to_sym or gem.groups.include? :default puts "Gem name: #{gem.name}" spec = Gem::Specification.find_by_name gem.name discover spec.gem_dir end end # Discover models in current rails app and load them discover Rails.root if defined? ActiveRecord # Create a content type entry for all Models ActiveRecord::Base.subclasses.each do |model| create_model model.name, without_habtm end end if defined? Mongoid Mongoid.models.each do |model| create_model model.name, without_habtm end end end |