Sha256: c34d6db712e56b64d77afed8c65081e11bcf0ab23b2615bcd6e8e65df5a728aa

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 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|
      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

    # Create a content type entry for all Models
    ActiveRecord::Base.subclasses.each do |model|
      ApplicationModels.find_or_create_by_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.2 lib/model_discovery/discovery.rb