Class: RailsERD::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_erd/cli.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ CLI

Returns a new instance of CLI.



160
161
162
163
# File 'lib/rails_erd/cli.rb', line 160

def initialize(path, options)
  @path, @options = path, options
  require "rails_erd/diagram/graphviz"
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



139
140
141
# File 'lib/rails_erd/cli.rb', line 139

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



139
140
141
# File 'lib/rails_erd/cli.rb', line 139

def path
  @path
end

Class Method Details

.startObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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

Instance Method Details

#startObject



165
166
167
168
169
170
171
# 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