Sha256: ff475a86b6a0f55148a8b6203a1405b35a8d4980fba17caf8fbb68237d4c7b58

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require "rails_model_visualizer/version"
require "rails_model_visualizer/templates"
require "rails_model_visualizer/model"
require "launchy"
require "fileutils"

class RMVisualizer

  def self.import_models
    if Rails.application
      Rails.application.eager_load!
      return ActiveRecord::Base.descendants.map do |rails_model|
        Model.new(rails_model)
      end
    else
      return []
    end
  end

  def self.print_models
    superclasses = {}
    RMVisualizer.import_models.each do |m|
      if superclasses[m.super_class]
        superclasses[m.super_class] += m.to_div
      else
        superclasses[m.super_class] = m.to_div
      end
    end

    body = ""
    superclasses.each do |superclass, model_div|
      body += "<div class=\"superclass\">#{superclass}
        #{model_div}
      </div>"
    end


    dirname = "docs/RMVisualizer"
    unless File.directory?(dirname)
      FileUtils.mkdir_p(dirname)
    end

    File.open("docs/RMVisualizer/output.html", 'w+') do |file|
      file.write(RMVisualizer.html(body))
    end

    File.open("docs/RMVisualizer/application.css", "w+") do |file|
      file.write(RMVisualizer.css)
    end

    puts "output.html created at docs/RMVisualizer folder"
    Launchy.open("docs/RMVisualizer/output.html")
    return nil
  end







end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_model_visualizer-0.1.2 lib/rails_model_visualizer.rb