Sha256: f175aa8888f8a88950a02ba2ebc02b679ad598fab8db475f6f4b8add269cf997

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

def say(message)
  puts message unless Rake.application.options.silent
end

namespace :erd do
  task :options do
    (RailsERD.options.keys.map(&:to_s) & ENV.keys).each do |option|
      RailsERD.options[option.to_sym] = case ENV[option]
      when "true", "yes" then true
      when "false", "no" then false
      when /,/ then ENV[option].split(/\s*,\s*/).map(&:to_sym)
      else ENV[option].to_sym
      end
    end
  end
  
  task :load_models do
    say "Loading Active Record models..."

    Rake::Task[:environment].invoke
    Rails.application.config.paths.app.models.paths.each do |model_path|
      Dir["#{model_path}/**/*.rb"].sort.each do |file|
        require_dependency file
      end
    end
  end
  
  task :generate => [:options, :load_models] do
    say "Generating Entity-Relationship Diagram..."

    require "rails_erd/diagram/graphviz"
    file = RailsERD::Diagram::Graphviz.create

    say "Done! Saved diagram to #{file}."
  end
end

desc "Generate an Entity-Relationship Diagram based on your models"
task :erd => "erd:generate"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-erd-0.4.0 lib/rails_erd/tasks.rake
rails-erd-0.3.0 lib/rails_erd/tasks.rake