class RailsERD::CLI
Attributes
options[R]
path[R]
Public Class Methods
new(path, options)
click to toggle source
# File lib/rails_erd/cli.rb, line 160 def initialize(path, options) @path, @options = path, options require "rails_erd/diagram/graphviz" end
start()
click to toggle source
# File lib/rails_erd/cli.rb, line 142 def start path = Choice.rest.first || Dir.pwd options = Choice.choices.each_with_object({}) do |(key, value), opts| if key.start_with? "no_" opts[key.gsub("no_", "").to_sym] = !value elsif value.to_s.include? "," opts[key.to_sym] = value.split(",").map(&:to_s) else opts[key.to_sym] = value end end if options[:config_file] && options[:config_file] != '' RailsERD.options = RailsERD.default_options.merge(Config.load(options[:config_file])) end new(path, options).start end
Public Instance Methods
start()
click to toggle source
# File lib/rails_erd/cli.rb, line 165 def start load_application create_diagram rescue Exception => e $stderr.puts "Failed: #{e.class}: #{e.message}" $stderr.puts e.backtrace.map { |t| " from #{t}" } if options[:debug] end
Private Instance Methods
create_diagram()
click to toggle source
# File lib/rails_erd/cli.rb, line 191 def create_diagram $stderr.puts "Generating entity-relationship diagram for #{ActiveRecord::Base.descendants.length} models..." file = RailsERD::Diagram::Graphviz.create(options) $stderr.puts "Diagram saved to '#{file}'." `open #{file}` if options[:open] end
load_application()
click to toggle source
# File lib/rails_erd/cli.rb, line 175 def load_application $stderr.puts "Loading application in '#{File.basename(path)}'..." begin environment_path = "#{path}/config/environment.rb" require environment_path rescue ::LoadError puts "Please create a file in '#{environment_path}' that loads your application environment." raise end if defined? Rails Rails.application.eager_load! Rails.application.config.eager_load_namespaces.each(&:eager_load!) if Rails.application.config.respond_to?(:eager_load_namespaces) end rescue TypeError end