Sha256: 67ac1598d22461f939d2f34f5db9eaa2f4978d7914a65d8fd79372658bbaa86e

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

module ModelDiscovery
  def self.build_table_list
    # 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|
      puts "Gem name: #{gem.name}"
      spec = Gem::Specification.find_by_name gem.name
      discover spec.gem_dir
    end

    # Discover models in current rails app and load them
    discover Rails.root

    # Create a content type entry for all Models
    ActiveRecord::Base.subclasses.each do |model|
      ApplicationModels.create(:model => model.to_s)
    end
  end

  private

  def self.discover(path)
    Dir["#{path}/app/models/**/*.rb"].each do |model_file|
      puts "File matched: #{model_file}"
      load model_file
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
model_discovery-0.2.0 lib/model_discovery/discovery.rb