Sha256: ed7e5d986cbda5e5321e1ddadb85e14c6bef9cfcb620ca16f13e5bab13191b3b

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'rails_erd/diagram/graphviz'

module DrawErd
  class Diagram
    class << self
      def schemas
        schemas = ActiveRecord::Base.connection.tables
        schemas.delete('schema_migrations')
        schemas.map! {|schema| schema.singularize.camelize}
        schemas.sort
      end

      def reset_migrations
        paths = ActiveRecord::Migrator.migrations_paths
        paths.each do |path|
          Dir.foreach(path) do |file|
            if match_data = /^(\d{3,})_(.+)\.rb$/.match(file)
              version = match_data[1].to_i
              ActiveRecord::Migrator.run(:down, paths, version)
              ActiveRecord::Migrator.run(:up, paths, version)
            end
          end
        end
      end
    end

    def initialize(path)
      @path = File.expand_path(path, Rails.root)
      FileUtils.mkdir_p(@path)
    end

    def create(title, domains=[], attributes=false)
      only = domains.map {|domain| domain.to_sym}
      options = {
        filetype: :png,
        attributes: attributes,
        title: false,
        only: only,
        filename: File.join(@path, title.to_s)
      }

      Rails.application.eager_load!
      RailsERD::Diagram::Graphviz.create(options)
    rescue => e
      Rails.logger.error(e)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
draw_erd-0.4.0 app/models/draw_erd/diagram.rb
draw_erd-0.3.0 app/models/draw_erd/diagram.rb
draw_erd-0.2.0 app/models/draw_erd/diagram.rb