Class: PryRails::ShowModel

Inherits:
Pry::ClassCommand
  • Object
show all
Defined in:
lib/pry-rails/commands/show_model.rb

Instance Method Summary collapse

Instance Method Details

#options(opt) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/pry-rails/commands/show_model.rb', line 8

def options(opt)
  opt.banner unindent <<-USAGE
    Usage: show-model <model name>

    show-model displays one model from the current Rails app.
  USAGE
end

#processObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pry-rails/commands/show_model.rb', line 16

def process
  Rails.application.eager_load!

  if args.empty?
    output.puts opts
    return
  end

  begin
    model = Object.const_get(args.first)
  rescue NameError
    output.puts "Couldn't find model #{args.first}!"
    return
  end

  formatter = PryRails::ModelFormatter.new

  case
  when defined?(ActiveRecord::Base) && model < ActiveRecord::Base
    output.puts formatter.format_active_record(model)
  when defined?(Mongoid::Document) && model < Mongoid::Document
    output.puts formatter.format_mongoid(model)
  else
    output.puts "Don't know how to show #{model}!"
  end
end