Class: RailsERD::CLI

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

Constant Summary collapse

SYMBOL_OPTIONS =

Options that should be converted to symbols

%i[generator mermaid_style filetype notation orientation].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ CLI

Returns a new instance of CLI.



203
204
205
206
207
208
209
210
211
212
# File 'lib/rails_erd/cli.rb', line 203

def initialize(path, options)
  @path, @options = path, options
  generator = options[:generator] || RailsERD.options[:generator]
  case generator
  when :mermaid  then require "rails_erd/diagram/mermaid"
  when :tbls     then require "rails_erd/diagram/tbls"
  when :graphviz then require "rails_erd/diagram/graphviz"
  else                require "rails_erd/diagram/mermaid"
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



176
177
178
# File 'lib/rails_erd/cli.rb', line 176

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



176
177
178
# File 'lib/rails_erd/cli.rb', line 176

def path
  @path
end

Class Method Details

.startObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/rails_erd/cli.rb', line 182

def start
  path = Choice.rest.first || Dir.pwd
  options = Choice.choices.each_with_object({}) do |(key, value), opts|
    key_sym = key.to_sym
    if key.start_with? "no_"
      opts[key.gsub("no_", "").to_sym] = !value
    elsif value.to_s.include? ","
      opts[key_sym] = value.split(",").map(&:to_s)
    elsif SYMBOL_OPTIONS.include?(key_sym) && value.is_a?(String)
      opts[key_sym] = value.to_sym
    else
      opts[key_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



214
215
216
217
218
219
220
# File 'lib/rails_erd/cli.rb', line 214

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