class Yml2erd::CLI

Public Instance Methods

convert(path) click to toggle source
# File lib/yml2erd/cli.rb, line 12
def convert(path)
  abort_if_graphviz_isnt_installed
  schema_structure = load_yml(path)
  opts = {
    output_path: options[:output_path],
    project_name: options[:projectname],
    output_style: options[:outputstyle]
  }
  Yml2erd::Diagram.create(schema_structure, opts)
  puts 'Successfully converted!'
end

Private Instance Methods

abort_if_graphviz_isnt_installed() click to toggle source

This method has a bug around `which gvpr`. That is because which command may not exist except UNIX based OS.

# File lib/yml2erd/cli.rb, line 39
def abort_if_graphviz_isnt_installed
  abort "GraphViz is not installed, please install graphviz from http://www.graphviz.org/Download..php \n\nOr you can get by\n   $ brew install graphviz    # on macOS\n   $ apt-get install graphviz # on Ubuntu" unless !`which gvpr`.empty?
end
abort_unless_yml(path) click to toggle source
# File lib/yml2erd/cli.rb, line 26
def abort_unless_yml(path)
  abort 'file must be a .yml file' unless path =~ /\.yml$/
end
load_yml(path) click to toggle source
# File lib/yml2erd/cli.rb, line 30
def load_yml(path)
  abort_unless_yml(path)
  abort "#{path} is not found, please check your .yml file path" unless File.exists?(path)
  yml = YAML.load_file(path)
  Yml2erd::Parser.parse(yml)
end