Sha256: a5bfc9aca381b26c3236d9cdc59d145c84868b5f6b6d071316441193e33df3d2

Contents?: true

Size: 1003 Bytes

Versions: 12

Compression:

Stored size: 1003 Bytes

Contents

# encoding: UTF-8

class PryRails::ShowModel < Pry::ClassCommand
  match "show-model"
  group "Rails"
  description "Show the given model."

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

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

  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
end

PryRails::Commands.add_command PryRails::ShowModel

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
pry-rails-0.3.11 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.10 lib/pry-rails/commands/show_model.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-rails-0.3.9/lib/pry-rails/commands/show_model.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-rails-0.3.9/lib/pry-rails/commands/show_model.rb
pry-rails-0.3.9 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.8 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.7 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.6 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.5 lib/pry-rails/commands/show_model.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/pry-rails-0.3.4/lib/pry-rails/commands/show_model.rb
pry-rails-0.3.4 lib/pry-rails/commands/show_model.rb
pry-rails-0.3.3 lib/pry-rails/commands/show_model.rb