pry-rails-0.3.9/0000755000175100017510000000000013626141525012500 5ustar pravipravipry-rails-0.3.9/scenarios.yml0000644000175100017510000000107213626141525015211 0ustar pravipraviproject: pryrails shared: from: ruby:2.4 cmd: "(bundle check || (gem install bundler && bundle install)) && bundle exec rake" service: volumes: - bundle_{{scenario_name}}:/usr/local/bundle environment: BUNDLE_GEMFILE: scenarios/{{scenario_name}}.gemfile volumes: bundle_{{scenario_name}}: scenarios: rails30: from: ruby:2.0 rails31: from: ruby:2.0 rails32: from: ruby:2.0 rails40: from: ruby:2.3 rails41: from: ruby:2.3 rails42: {} rails50: {} rails51: {} rails52: {} rails60: from: ruby:2.5 pry-rails-0.3.9/.gitignore0000644000175100017510000000010413626141525014463 0ustar pravipravi*.gem .bundle Gemfile.lock pkg/* spec/log spec/tmp scenarios/*.lock pry-rails-0.3.9/Rakefile0000644000175100017510000000206113626141525014144 0ustar pravipravirequire "rubygems" require "bundler/setup" require "bundler/gem_tasks" require "rake/testtask" require "appraisal" Rake::TestTask.new do |t| t.libs.concat %w(pry-rails spec) t.pattern = "spec/*_spec.rb" end desc 'Start the Rails server' task :server => :development_env do require 'rails/commands/server' Rails::Server.start( :server => 'WEBrick', :environment => 'development', :Host => '0.0.0.0', :Port => 3000, :config => 'config/config.ru' ) end desc 'Start the Rails console' task :console => :development_env do if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR >= 6 require 'rails/command' require 'rails/commands/console/console_command' else require 'rails/commands/console' end Rails::Console.start(Rails.application) end task :development_env do ENV['RAILS_ENV'] = 'development' require File.expand_path('../spec/config/environment', __FILE__) Dir.chdir(Rails.application.root) end # Must invoke indirectly, using `rake appraisal`. task :default => [:test] pry-rails-0.3.9/spec/0000755000175100017510000000000013626141525013432 5ustar pravipravipry-rails-0.3.9/spec/recognize_path_spec.rb0000644000175100017510000000324213626141525017773 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' describe "recognize-path" do before do FooController = Class.new(ActionController::Base) BoomsController = Class.new(ActionController::Base) routes = Rails.application.routes routes.draw { root(:to => 'foo#index', :constraints => {:host => 'example.com'}) resources :booms } routes.finalize! end after do [:FooController, :BoomsController].each { |const| Object.__send__(:remove_const, const) } end it 'fails gracefully if no path is given' do output = mock_pry('recognize-path', 'exit-all') output.must_equal \ "Error: The command 'recognize-path' requires an argument.\n" end it "prints info about controller/action that is bound to the given path" do output = mock_pry('recognize-path example.com', 'exit-all') output.must_match(/controller.+foo/) output.must_match(/action.+index/) end it "accepts short path" do output = mock_pry('recognize-path /booms/1/edit', 'exit-all') output.must_match(/action.+edit/) output.must_match(/controller.+booms/) output.must_match(/id.+1/) end it "accepts -m switch" do output = mock_pry('recognize-path example.com/booms -m post', 'exit-all') output.must_match(/controller.+booms/) output.must_match(/action.+create/) end it "doesn't accept unknown methods" do output = mock_pry('recognize-path example.com/booms -m posty', 'exit-all') output.must_match 'Unknown HTTP method: posty' end it "doesn't accept unknown routes" do output = mock_pry('recognize-path bing/bang/bong', 'exit-all') output.must_match 'No route matches "http://bing/bang/bong"' end end pry-rails-0.3.9/spec/show_routes_spec.rb0000644000175100017510000000157313626141525017360 0ustar pravipravi# encoding: UTF-8 # We can just have a smoke test for this one since it's mostly using built-in # Rails functionality. Plus the output is a bit different between Rails # versions, so that's annoying. require 'spec_helper' describe "show-routes" do it "should print a list of routes" do output = mock_pry('show-routes', 'exit-all') output.must_match %r{edit_pokemon GET /pokemon/edit} end it "should print a list of routes which include grep option" do output = mock_pry('show-routes -G edit', 'exit-all') output.must_match %r{edit_pokemon GET /pokemon/edit} output.must_match %r{ edit_beer GET /beer/edit} end it "should filter list based on multiple grep options" do output = mock_pry('show-routes -G edit -G pokemon', 'exit-all') output.must_match %r{edit_pokemon GET /pokemon/edit} output.wont_match %r{edit_beer} end end pry-rails-0.3.9/spec/config/0000755000175100017510000000000013626141525014677 5ustar pravipravipry-rails-0.3.9/spec/config/database.yml0000644000175100017510000000014713626141525017170 0ustar pravipravidevelopment: adapter: sqlite3 database: ":memory:" test: adapter: sqlite3 database: ":memory:" pry-rails-0.3.9/spec/config/environment.rb0000644000175100017510000000254613626141525017577 0ustar pravipravirequire 'rails' require 'rails/all' require 'active_support/core_ext' require 'pry-rails' begin require 'mongoid' rescue LoadError # Mongoid doesn't support Rails 3.0 end # Initialize our test app class TestApp < Rails::Application config.active_support.deprecation = :log config.eager_load = false config.secret_token = 'a' * 100 config.root = File.expand_path('../..', __FILE__) end TestApp.initialize! # Create in-memory database ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :pokemons do |t| t.string :name t.binary :caught t.string :species t.string :abilities end create_table :hackers do |t| t.integer :social_ability end create_table :beers do |t| t.string :name t.string :type t.integer :rating t.integer :ibu t.integer :abv end end # Define models class Beer < ActiveRecord::Base belongs_to :hacker end class Hacker < ActiveRecord::Base has_many :pokemons has_many :beers end class Pokemon < ActiveRecord::Base belongs_to :hacker has_many :beers, :through => :hacker end if defined?(Mongoid) class Artist include Mongoid::Document field :name, :type => String embeds_one :beer embeds_many :instruments end class Instrument include Mongoid::Document field :name, :type => String embedded_in :artist end end pry-rails-0.3.9/spec/config/routes.rb0000644000175100017510000000021213626141525016540 0ustar pravipraviTestApp.routes.draw do resource :pokemon, :beer get 'exit' => proc { exit! } get 'pry' => proc { binding.pry; [200, {}, ['']] } end pry-rails-0.3.9/spec/config/config.ru0000644000175100017510000000002613626141525016512 0ustar pravipravirun Rails.application pry-rails-0.3.9/spec/show_middleware_spec.rb0000644000175100017510000000053313626141525020147 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' describe "show-middleware" do it "should print a list of middleware" do output = mock_pry('show-middleware', 'exit-all') output.must_match %r{^use ActionDispatch::Static$} output.must_match %r{^use ActionDispatch::ShowExceptions$} output.must_match %r{^run TestApp.routes\Z} end end pry-rails-0.3.9/spec/find_route_spec.rb0000644000175100017510000000234613626141525017134 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' describe "find-route" do before do routes = Rails.application.routes routes.draw { namespace :admin do resources :users resources :images end } routes.finalize! end it 'returns the route for a single action' do output = mock_pry('find-route Admin::UsersController#show', 'exit-all') output.must_match(/show GET/) output.wont_match(/index GET/) end it 'returns all the routes for a controller' do output = mock_pry('find-route Admin::UsersController', 'exit-all') output.must_match(/index GET/) output.must_match(/show GET/) output.must_match(/new GET/) output.must_match(/edit GET/) output.must_match(/update (PATCH|PUT)/) output.must_match(/update PUT/) output.must_match(/destroy DELETE/) end it 'returns all routes for controllers under a namespace' do output = mock_pry('find-route Admin', 'exit-all') output.must_match(/Routes for Admin::UsersController/) output.must_match(/Routes for Admin::ImagesController/) end it 'returns no routes found when controller is not recognized' do output = mock_pry('find-route Foo', 'exit-all') output.must_match(/No routes found/) end end pry-rails-0.3.9/spec/show_models_spec.rb0000644000175100017510000000355513626141525017324 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' describe "show-models" do it "should print a list of models" do output = mock_pry('show-models', 'exit-all') ar_models = <= 5 expected_output = internal_models + expected_output end output.must_equal expected_output end it "should highlight the given phrase with --grep" do begin Pry.color = true output = mock_pry('show-models --grep rating', 'exit-all') output.must_include "Beer" output.must_include "\e[7mrating\e[27m" output.wont_include "Pokemon" if defined?(Mongoid) output.wont_include "Artist" end ensure Pry.color = false end end if defined?(Mongoid) it "should also filter for mongoid" do output = mock_pry('show-models --grep beer', 'exit-all') output.must_include 'Artist' end end end pry-rails-0.3.9/spec/railtie_spec.rb0000644000175100017510000000161213626141525016422 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR >= 6 require 'rails/command' require 'rails/commands/console/console_command' else require 'rails/commands/console' end describe PryRails::Railtie do it 'should start Pry instead of IRB and make the helpers available' do # Yes, I know this is horrible. begin $called_start = false real_pry = Pry silence_warnings do ::Pry = Class.new do def self.start(*) $called_start = true end end end Rails::Console.start(Rails.application) assert $called_start ensure silence_warnings do ::Pry = real_pry end end %w(app helper reload!).each do |helper| TOPLEVEL_BINDING.eval("respond_to?(:#{helper}, true)").must_equal true end end end pry-rails-0.3.9/spec/show_model_spec.rb0000644000175100017510000000252413626141525017134 0ustar pravipravi# encoding: UTF-8 require 'spec_helper' describe "show-model" do it "should print one ActiveRecord model" do output = mock_pry('show-model Beer', 'exit-all') expected = < Pry::Hooks.new) end output.string end pry-rails-0.3.9/pry-rails.gemspec0000644000175100017510000000160513626141525015771 0ustar pravipravi# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "pry-rails/version" Gem::Specification.new do |s| s.name = "pry-rails" s.version = PryRails::VERSION s.authors = ["Robin Wenglewski"] s.email = ["robin@wenglewski.de"] s.homepage = "https://github.com/rweng/pry-rails" s.summary = %q{Use Pry as your rails console} s.license = "MIT" s.required_ruby_version = ">= 1.9.1" # s.description = %q{TODO: Write a gem description} # s.rubyforge_project = "pry-rails" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] s.add_dependency "pry", ">= 0.10.4" s.add_development_dependency "appraisal" s.add_development_dependency "minitest" end pry-rails-0.3.9/lib/0000755000175100017510000000000013626141525013246 5ustar pravipravipry-rails-0.3.9/lib/pry-rails/0000755000175100017510000000000013626141525015170 5ustar pravipravipry-rails-0.3.9/lib/pry-rails/commands.rb0000644000175100017510000000033613626141525017320 0ustar pravipravi# encoding: UTF-8 PryRails::Commands = Pry::CommandSet.new command_glob = File.expand_path('../commands/*.rb', __FILE__) Dir[command_glob].each do |command| require command end Pry.commands.import PryRails::Commands pry-rails-0.3.9/lib/pry-rails/commands/0000755000175100017510000000000013626141525016771 5ustar pravipravipry-rails-0.3.9/lib/pry-rails/commands/show_routes.rb0000644000175100017510000000540513626141525021703 0ustar pravipraviclass PryRails::ShowRoutes < Pry::ClassCommand match 'show-routes' group 'Rails' description 'Show all routes in match order.' banner <<-BANNER Usage: show-routes [-G] show-routes displays the current Rails app's routes. BANNER def options(opt) opt.on :G, "grep", "Filter output by regular expression", :argument => true, :as => Array end def process Rails.application.reload_routes! all_routes = Rails.application.routes.routes formatted = if Rails::VERSION::MAJOR >= 6 process_rails_6_and_higher(all_routes) elsif Rails::VERSION::MAJOR == 4 || Rails::VERSION::MAJOR == 5 process_rails_4_and_5(all_routes) elsif Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR >= 2 process_rails_3_2(all_routes) else process_rails_3_0_and_3_1(all_routes) end output.puts grep_routes(formatted).join("\n") end # Takes an array of lines. Returns a list filtered by the conditions in # `opts[:G]`. def grep_routes(formatted) return formatted unless opts[:G] grep_opts = opts[:G] grep_opts.reduce(formatted) do |lines, pattern| lines.grep(Regexp.new(pattern)) end end # Cribbed from https://github.com/rails/rails/blob/3-1-stable/railties/lib/rails/tasks/routes.rake def process_rails_3_0_and_3_1(all_routes) routes = all_routes.collect do |route| reqs = route.requirements.dup reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/ reqs = reqs.empty? ? "" : reqs.inspect {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path, :reqs => reqs} end # Skip the route if it's internal info route routes.reject! { |r| r[:path] =~ %r{/rails/info/properties|^/assets} } name_width = routes.map{ |r| r[:name].length }.max verb_width = routes.map{ |r| r[:verb].length }.max path_width = routes.map{ |r| r[:path].length }.max routes.map do |r| "#{r[:name].rjust(name_width)} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs]}" end end def process_rails_3_2(all_routes) require 'rails/application/route_inspector' Rails::Application::RouteInspector.new.format(all_routes) end def process_rails_4_and_5(all_routes) require 'action_dispatch/routing/inspector' ActionDispatch::Routing::RoutesInspector. new(all_routes). format(ActionDispatch::Routing::ConsoleFormatter.new). split(/\n/) end def process_rails_6_and_higher(all_routes) require 'action_dispatch/routing/inspector' ActionDispatch::Routing::RoutesInspector. new(all_routes). format(ActionDispatch::Routing::ConsoleFormatter::Sheet.new). split(/\n/) end PryRails::Commands.add_command(self) end pry-rails-0.3.9/lib/pry-rails/commands/show_models.rb0000644000175100017510000000356713626141525021654 0ustar pravipravi# encoding: UTF-8 class PryRails::ShowModels < Pry::ClassCommand match "show-models" group "Rails" description "Show all models." def options(opt) opt.banner unindent <<-USAGE Usage: show-models show-models displays the current Rails app's models. USAGE opt.on :G, "grep", "Filter output by regular expression", :argument => true end def process Rails.application.eager_load! @formatter = PryRails::ModelFormatter.new display_activerecord_models display_mongoid_models end def display_activerecord_models return unless defined?(ActiveRecord::Base) models = ActiveRecord::Base.descendants models.sort_by(&:to_s).each do |model| print_unless_filtered @formatter.format_active_record(model) end end def display_mongoid_models return unless defined?(Mongoid::Document) models = [] ObjectSpace.each_object do |o| # If this is deprecated, calling any methods on it will emit a warning, # so just back away slowly. next if ActiveSupport::Deprecation::DeprecationProxy === o is_model = false begin is_model = o.class == Class && o.ancestors.include?(Mongoid::Document) rescue # If it's a weird object, it's not what we want anyway. end models << o if is_model end models.sort_by(&:to_s).each do |model| print_unless_filtered @formatter.format_mongoid(model) end end def print_unless_filtered(str) if opts.present?(:G) return unless str =~ grep_regex str = colorize_matches(str) # :( end output.puts str end def colorize_matches(string) if Pry.color string.to_s.gsub(grep_regex) { |s| "\e[7m#{s}\e[27m" } else string end end def grep_regex @grep_regex ||= Regexp.new(opts[:G], Regexp::IGNORECASE) end end PryRails::Commands.add_command PryRails::ShowModels pry-rails-0.3.9/lib/pry-rails/commands/recognize_path.rb0000644000175100017510000000167713626141525022332 0ustar pravipraviclass PryRails::RecognizePath < Pry::ClassCommand match 'recognize-path' group 'Rails' description 'See which route matches a URL.' command_options argument_required: true banner <<-BANNER Usage: recognize-path [-m|--method METHOD] Verifies that a given path is mapped to the right controller and action. recognize-path example.com recognize-path example.com -m post BANNER def options(opt) opt.on :m, :method, "Methods", :argument => true end def process(path) method = (opts.m? ? opts[:m] : :get) routes = Rails.application.routes begin info = routes.recognize_path("http://#{path}", :method => method) rescue ActionController::UnknownHttpMethod output.puts "Unknown HTTP method: #{method}" rescue ActionController::RoutingError => e output.puts e end output.puts Pry::Helpers::BaseHelpers.colorize_code(info) end PryRails::Commands.add_command(self) end pry-rails-0.3.9/lib/pry-rails/commands/find_route.rb0000644000175100017510000000472413626141525021463 0ustar pravipraviclass PryRails::FindRoute < Pry::ClassCommand match 'find-route' group 'Rails' description 'See which URLs match a given Controller.' banner <<-BANNER Usage: find-route Returns the URL(s) that match a given controller or controller action. find-route MyController#show #=> The URL that matches the MyController show action find-route MyController #=> All the URLs that hit MyController find-route Admin #=> All the URLs that hit the Admin namespace find-route Com #=> All the URLS whose controller regex matches /Comm/, e.g CommentsController BANNER def process(controller) controller_string = controller.to_s if single_action?(controller_string) single_action(controller_string) else all_actions(controller_string) end end private def single_action(controller) show_routes { |route| route.defaults == controller_and_action_from(controller) } end def all_actions(controller) show_routes do |route| route.defaults[:controller].to_s =~ /#{normalize_controller_name(controller)}/ end end def controller_and_action_from(controller_and_action) controller, action = controller_and_action.split("#") {controller: normalize_controller_name(controller), action: action} end def routes Rails.application.routes.routes end def normalize_controller_name(controller) controller.underscore.chomp('_controller') end def show_routes(&block) all_routes = routes.select(&block) if all_routes.any? grouped_routes = all_routes.group_by { |route| route.defaults[:controller] } result = grouped_routes.each_with_object("") do |(controller, routes), res| res << "Routes for " + text.bold(controller.to_s.camelize + "Controller") + "\n" res << "--\n" routes.each do |route| spec = route.path.is_a?(String) ? route.path : route.path.spec res << "#{route.defaults[:action]} #{text.bold(verb_for(route))} #{spec} #{route_helper(route.name)}" + "\n" end res << "\n" end stagger_output result else output.puts "No routes found." end end def route_helper(name) name && "[#{name}]" end def verb_for(route) %w(GET PUT POST PATCH DELETE).find { |v| route.verb === v } end def single_action?(controller) controller =~ /#/ end PryRails::Commands.add_command(self) end PryRails::Commands.alias_command "find-routes", "find-route" pry-rails-0.3.9/lib/pry-rails/commands/show_model.rb0000644000175100017510000000175313626141525021464 0ustar pravipravi# 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 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 pry-rails-0.3.9/lib/pry-rails/commands/show_middleware.rb0000644000175100017510000000375313626141525022503 0ustar pravipraviclass PryRails::ShowMiddleware < Pry::ClassCommand match 'show-middleware' group 'Rails' description 'Show all middleware (that Rails knows about).' banner <<-BANNER Usage: show-middleware [-G] show-middleware shows the Rails app's middleware. If this pry REPL is attached to a Rails server, the entire middleware stack is displayed. Otherwise, only the middleware Rails knows about is printed. BANNER def options(opt) opt.on :G, "grep", "Filter output by regular expression", :argument => true end def process # assumes there is only one Rack::Server instance server = nil ObjectSpace.each_object(Rack::Server) do |object| server = object end middlewares = [] if server stack = server.instance_variable_get("@wrapped_app") middlewares << stack.class.to_s while stack.instance_variable_defined?("@app") do stack = stack.instance_variable_get("@app") # Rails 3.0 uses the Application class rather than the application # instance itself, so we grab the instance. stack = Rails.application if stack == Rails.application.class middlewares << stack.class.to_s if stack != Rails.application end else middleware_names = Rails.application.middleware.map do |middleware| # After Rails 3.0, the middleware are wrapped in a special class # that responds to #name. if middleware.respond_to?(:name) middleware.name else middleware.inspect end end middlewares.concat middleware_names end middlewares << Rails.application.class.to_s print_middleware middlewares.grep(Regexp.new(opts[:G] || ".")) end def print_middleware(middlewares) middlewares.each do |middleware| string = if middleware == Rails.application.class.to_s "run #{middleware}.routes" else "use #{middleware}" end output.puts string end end PryRails::Commands.add_command(self) end pry-rails-0.3.9/lib/pry-rails/model_formatter.rb0000644000175100017510000000611313626141525020701 0ustar pravipravi# encoding: UTF-8 module PryRails class ModelFormatter def format_active_record(model) out = [] out.push format_model_name model if model.table_exists? model.columns.each do |column| out.push format_column column.name, column.type end else out.push format_error "Table doesn't exist" end reflections = model.reflections.sort_by do |other_model, reflection| [reflection.macro.to_s, other_model.to_s] end reflections.each do |other_model, reflection| options = [] if reflection.options[:through].present? options << "through #{text.blue ":#{reflection.options[:through]}"}" end if reflection.options[:class_name].present? options << "class_name #{text.green ":#{reflection.options[:class_name]}"}" end if reflection.options[:foreign_key].present? options << "foreign_key #{text.red ":#{reflection.options[:foreign_key]}"}" end out.push format_association reflection.macro, other_model, options end out.join("\n") end def format_mongoid(model) out = [] out.push format_model_name model model.fields.values.sort_by(&:name).each do |column| out.push format_column column.name, column.options[:type] end model.relations.each do |other_model, ref| options = [] options << 'autosave' if ref.options[:autosave] || ref.autosave? options << 'autobuild' if ref.options[:autobuild] || ref.autobuilding? options << 'validate' if ref.options[:validate] || ref.validate? if ref.options[:dependent] || ref.dependent options << "dependent-#{ref.options[:dependent] || ref.dependent}" end out.push format_association \ kind_of_relation(ref.relation), other_model, options end out.join("\n") end def format_model_name(model) text.bright_blue model end def format_column(name, type) " #{name}: #{text.green type}" end def format_association(type, other, options = []) options_string = (options.any?) ? " (#{options.join(', ')})" : '' " #{type} #{text.blue ":#{other}"}#{options_string}" end def format_error(message) " #{text.red message}" end def kind_of_relation(relation) case relation.to_s.sub(/^Mongoid::(Relations::|Association::)/, '') when 'Referenced::Many', 'Referenced::HasMany::Proxy' 'has_many' when 'Referenced::One', 'Referenced::HasOne::Proxy' 'has_one' when 'Referenced::In', 'Referenced::BelongsTo::Proxy' 'belongs_to' when 'Referenced::HasAndBelongsToMany::Proxy' 'has_and_belongs_to_many' when 'Embedded::Many', 'Embedded::EmbedsMany::Proxy' 'embeds_many' when 'Embedded::One', 'Embedded::EmbedsOne::Proxy' 'embeds_one' when 'Embedded::In', 'Embedded::EmbeddedIn::Proxy' 'embedded_in' else '(unknown relation)' end end private def text Pry::Helpers::Text end end end pry-rails-0.3.9/lib/pry-rails/console.rb0000644000175100017510000000014513626141525017157 0ustar pravipravi# encoding: UTF-8 require 'pry-rails/version' if defined?(Rails) require 'pry-rails/railtie' end pry-rails-0.3.9/lib/pry-rails/version.rb0000644000175100017510000000007313626141525017202 0ustar pravipravi# encoding: UTF-8 module PryRails VERSION = "0.3.9" end pry-rails-0.3.9/lib/pry-rails/railtie.rb0000644000175100017510000000130113626141525017141 0ustar pravipravi# encoding: UTF-8 module PryRails class Railtie < Rails::Railtie console do require 'pry' require 'pry-rails/commands' if Rails::VERSION::MAJOR == 3 Rails::Console::IRB = Pry unless defined? Pry::ExtendCommandBundle Pry::ExtendCommandBundle = Module.new end end if Rails::VERSION::MAJOR >= 4 Rails.application.config.console = Pry end if (Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR >= 2) || Rails::VERSION::MAJOR >= 4 require "rails/console/app" require "rails/console/helpers" TOPLEVEL_BINDING.eval('self').extend ::Rails::ConsoleMethods end end end end pry-rails-0.3.9/lib/pry-rails/prompt.rb0000644000175100017510000000323213626141525017036 0ustar pravipravimodule PryRails class Prompt class << self def formatted_env if Rails.env.production? bold_env = Pry::Helpers::Text.bold(Rails.env) Pry::Helpers::Text.red(bold_env) elsif Rails.env.development? Pry::Helpers::Text.green(Rails.env) else Rails.env end end def project_name if Rails::VERSION::MAJOR >= 6 Rails.application.class.module_parent_name.underscore else Rails.application.class.parent_name.underscore end end end end desc = "Includes the current Rails environment and project folder name.\n" \ "[1] [project_name][Rails.env] pry(main)>" if Pry::Prompt.respond_to?(:add) Pry::Prompt.add 'rails', desc, %w(> *) do |target_self, nest_level, pry, sep| "[#{pry.input_ring.size}] " \ "[#{Prompt.project_name}][#{Prompt.formatted_env}] " \ "#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \ "#{":#{nest_level}" unless nest_level.zero?}#{sep} " end else draw_prompt = lambda do |target_self, nest_level, pry, sep| "[#{pry.input_array.size}] " \ "[#{Prompt.project_name}][#{Prompt.formatted_env}] " \ "#{pry.config.prompt_name}(#{Pry.view_clip(target_self)})" \ "#{":#{nest_level}" unless nest_level.zero?}#{sep} " end prompts = [ proc do |target_self, nest_level, pry| draw_prompt.call(target_self, nest_level, pry, '>') end, proc do |target_self, nest_level, pry| draw_prompt.call(target_self, nest_level, pry, '*') end ] Pry::Prompt::MAP["rails"] = {value: prompts, description: desc} end end pry-rails-0.3.9/lib/pry-rails.rb0000644000175100017510000000036213626141525015516 0ustar pravipravi# encoding: UTF-8 require 'pry' require 'pry-rails/version' if defined?(Rails) && !ENV['DISABLE_PRY_RAILS'] require 'pry-rails/railtie' require 'pry-rails/commands' require 'pry-rails/model_formatter' require 'pry-rails/prompt' end pry-rails-0.3.9/scenarios/0000755000175100017510000000000013626141525014466 5ustar pravipravipry-rails-0.3.9/scenarios/rails31.dockerfile0000644000175100017510000000023213626141525017772 0ustar pravipraviFROM ruby:2.0 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails52.dockerfile0000644000175100017510000000023213626141525017775 0ustar pravipraviFROM ruby:2.4 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails31.gemfile0000644000175100017510000000017313626141525017277 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 3.1.0" gem "mongoid" gem "sqlite3" gem "test-unit" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails60.dockerfile0000644000175100017510000000023213626141525017774 0ustar pravipraviFROM ruby:2.5 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails40.dockerfile0000644000175100017510000000023213626141525017772 0ustar pravipraviFROM ruby:2.3 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails41.dockerfile0000644000175100017510000000023213626141525017773 0ustar pravipraviFROM ruby:2.3 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails51.gemfile0000644000175100017510000000015313626141525017277 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 5.1.0" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails52.gemfile0000644000175100017510000000015313626141525017300 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 5.2.0" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails30.dockerfile0000644000175100017510000000023213626141525017771 0ustar pravipraviFROM ruby:2.0 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails32.dockerfile0000644000175100017510000000023213626141525017773 0ustar pravipraviFROM ruby:2.0 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails42.docker-compose.yml0000644000175100017510000000050213626141525021377 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails42.dockerfile image: pryrails_scenario_rails42 volumes: - "..:/scenario" - "bundle_rails42:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails42.gemfile volumes: bundle_rails42: {} pry-rails-0.3.9/scenarios/rails32.gemfile0000644000175100017510000000017313626141525017300 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 3.2.0" gem "mongoid" gem "sqlite3" gem "test-unit" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails51.docker-compose.yml0000644000175100017510000000050213626141525021377 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails51.dockerfile image: pryrails_scenario_rails51 volumes: - "..:/scenario" - "bundle_rails51:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails51.gemfile volumes: bundle_rails51: {} pry-rails-0.3.9/scenarios/rails50.gemfile0000644000175100017510000000015313626141525017276 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 5.0.0" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails60.docker-compose.yml0000644000175100017510000000050213626141525021377 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails60.dockerfile image: pryrails_scenario_rails60 volumes: - "..:/scenario" - "bundle_rails60:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails60.gemfile volumes: bundle_rails60: {} pry-rails-0.3.9/scenarios/rails51.dockerfile0000644000175100017510000000023213626141525017774 0ustar pravipraviFROM ruby:2.4 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails50.dockerfile0000644000175100017510000000023213626141525017773 0ustar pravipraviFROM ruby:2.4 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails42.dockerfile0000644000175100017510000000023213626141525017774 0ustar pravipraviFROM ruby:2.4 RUN mkdir -p /scenario WORKDIR /scenario ENV LANG=C.UTF-8 CMD (bundle check || (gem install bundler && bundle install)) && bundle exec rake pry-rails-0.3.9/scenarios/rails50.docker-compose.yml0000644000175100017510000000050213626141525021376 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails50.dockerfile image: pryrails_scenario_rails50 volumes: - "..:/scenario" - "bundle_rails50:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails50.gemfile volumes: bundle_rails50: {} pry-rails-0.3.9/scenarios/rails41.gemfile0000644000175100017510000000015313626141525017276 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 4.1.0" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails52.docker-compose.yml0000644000175100017510000000050213626141525021400 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails52.dockerfile image: pryrails_scenario_rails52 volumes: - "..:/scenario" - "bundle_rails52:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails52.gemfile volumes: bundle_rails52: {} pry-rails-0.3.9/scenarios/rails40.gemfile0000644000175100017510000000013513626141525017275 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 4.0.0" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails31.docker-compose.yml0000644000175100017510000000050213626141525021375 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails31.dockerfile image: pryrails_scenario_rails31 volumes: - "..:/scenario" - "bundle_rails31:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails31.gemfile volumes: bundle_rails31: {} pry-rails-0.3.9/scenarios/rails41.docker-compose.yml0000644000175100017510000000050213626141525021376 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails41.dockerfile image: pryrails_scenario_rails41 volumes: - "..:/scenario" - "bundle_rails41:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails41.gemfile volumes: bundle_rails41: {} pry-rails-0.3.9/scenarios/rails42.gemfile0000644000175100017510000000015313626141525017277 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 4.2.0" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails32.docker-compose.yml0000644000175100017510000000050213626141525021376 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails32.dockerfile image: pryrails_scenario_rails32 volumes: - "..:/scenario" - "bundle_rails32:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails32.gemfile volumes: bundle_rails32: {} pry-rails-0.3.9/scenarios/rails60.gemfile0000644000175100017510000000016613626141525017303 0ustar pravipravisource "https://rubygems.org" gem "rails", github: "rails/rails" gem "mongoid" gem "sqlite3" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails40.docker-compose.yml0000644000175100017510000000050213626141525021375 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails40.dockerfile image: pryrails_scenario_rails40 volumes: - "..:/scenario" - "bundle_rails40:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails40.gemfile volumes: bundle_rails40: {} pry-rails-0.3.9/scenarios/rails30.gemfile0000644000175100017510000000015513626141525017276 0ustar pravipravisource "https://rubygems.org" gem "rails", "~> 3.0.0" gem "sqlite3" gem "test-unit" gemspec :path => "../" pry-rails-0.3.9/scenarios/rails30.docker-compose.yml0000644000175100017510000000050213626141525021374 0ustar pravipravi--- version: "2" services: scenario: build: context: .. dockerfile: scenarios/rails30.dockerfile image: pryrails_scenario_rails30 volumes: - "..:/scenario" - "bundle_rails30:/usr/local/bundle" environment: BUNDLE_GEMFILE: scenarios/rails30.gemfile volumes: bundle_rails30: {} pry-rails-0.3.9/Gemfile0000644000175100017510000000013613626141525013773 0ustar pravipravisource "https://rubygems.org" # Specify your gem's dependencies in pry-rails.gemspec gemspec pry-rails-0.3.9/LICENCE0000644000175100017510000000204313626141525013464 0ustar pravipraviCopyright (c) 2012 Robin Wenglewski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.pry-rails-0.3.9/Readme.md0000644000175100017510000000752013626141525014223 0ustar pravipravi# Description Avoid repeating yourself, use pry-rails instead of copying the initializer to every rails project. This is a small gem which causes `rails console` to open [pry](http://pry.github.com/). It therefore depends on *pry*. # Prerequisites - A Rails >= 3.0 Application - Ruby >= 1.9 # Installation Add this line to your gemfile: gem 'pry-rails', :group => :development `bundle install` and enjoy pry. # Usage ``` $ rails console [1] pry(main)> show-routes pokemon POST /pokemon(.:format) pokemons#create new_pokemon GET /pokemon/new(.:format) pokemons#new edit_pokemon GET /pokemon/edit(.:format) pokemons#edit GET /pokemon(.:format) pokemons#show PUT /pokemon(.:format) pokemons#update DELETE /pokemon(.:format) pokemons#destroy beer POST /beer(.:format) beers#create new_beer GET /beer/new(.:format) beers#new edit_beer GET /beer/edit(.:format) beers#edit GET /beer(.:format) beers#show PUT /beer(.:format) beers#update DELETE /beer(.:format) beers#destroy [2] pry(main)> show-routes --grep beer beer POST /beer(.:format) beers#create new_beer GET /beer/new(.:format) beers#new edit_beer GET /beer/edit(.:format) beers#edit GET /beer(.:format) beers#show PUT /beer(.:format) beers#update DELETE /beer(.:format) beers#destroy [3] pry(main)> show-routes --grep new new_pokemon GET /pokemon/new(.:format) pokemons#new new_beer GET /beer/new(.:format) beers#new [4] pry(main)> show-models Beer id: integer name: string type: string rating: integer ibu: integer abv: integer created_at: datetime updated_at: datetime belongs_to hacker Hacker id: integer social_ability: integer created_at: datetime updated_at: datetime has_many pokemons has_many beers Pokemon id: integer name: string caught: binary species: string abilities: string created_at: datetime updated_at: datetime belongs_to hacker has_many beers through hacker $ DISABLE_PRY_RAILS=1 rails console irb(main):001:0> ``` ## Custom Rails prompt If you want to permanently include the current Rails environment and project name in the Pry prompt, put the following lines in your project's `.pryrc`: ```ruby Pry.config.prompt = Pry::Prompt[:rails][:value] ``` If `.pryrc` could be loaded without pry-rails being available or installed, guard against setting `Pry.config.prompt` to `nil`: ```ruby if Pry::Prompt[:rails] Pry.config.prompt = Pry::Prompt[:rails][:value] end ``` Check out `change-prompt --help` for information about temporarily changing the prompt for the current Pry session. # Developing and Testing This repo uses [Roadshow] to generate a [Docker Compose] file for each supported version of Rails (with a compatible version of Ruby for each one). To run specs across all versions, you can either [get the Roadshow tool] and run `roadshow run`, or use Docker Compose directly: ``` $ for fn in scenarios/*.docker-compose-yml; do docker-compose -f $fn run --rm scenario; done ``` You can also manually run the Rails console and server on each version with `roadshow run rake console` and `roadshow run rake server`, or run them on a specific version with, e.g., `roadshow run -s rails40 rake console`. To update the set of scenarios, edit `scenarios.yml` and run `roadshow generate`, although the Gemfiles in the `scenarios` directory need to be maintained manually. [Roadshow]: https://github.com/rf-/roadshow [Docker Compose]: https://docs.docker.com/compose/ [get the Roadshow tool]: https://github.com/rf-/roadshow/releases # Alternative If you want to enable pry everywhere, make sure to check out [pry everywhere](http://lucapette.me/pry-everywhere).