Skip to content

Instantly share code, notes, and snippets.

@stevobengtson
Last active June 22, 2017 19:21
Show Gist options
  • Save stevobengtson/f25a303d4eb1c6967465cdd69e059de7 to your computer and use it in GitHub Desktop.
Save stevobengtson/f25a303d4eb1c6967465cdd69e059de7 to your computer and use it in GitHub Desktop.
My PryRC File for RubyOnRails
# place this file in ~/.pryrc
# vim FTW - you can use 'mate' or whichever your prefer
Pry.config.editor = 'vim'
Pry.config.hooks.add_hook :after_session, :say_bye do
puts "bye-bye" if Pry.active_sessions == 1
end
# Prompt with ruby version
Pry.prompt = [proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]
# Toys methods
# See https://gist.github.com/807492
class Array
def self.toy(n=10, &block)
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end
end
class Hash
def self.toy(n=10)
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
end
end
if defined?(Rails) && Rails.env
require 'logger'# place this file in ~/.pryrc
# vim FTW - you can use 'mate' or whichever your prefer
Pry.config.editor = 'vim'
Pry.config.hooks.add_hook :after_session, :say_bye do
puts "bye-bye" if Pry.active_sessions == 1
end
# Prompt with ruby version
Pry.prompt = [proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} > " }, proc { |obj, nest_level, _| "#{RUBY_VERSION} (#{obj}):#{nest_level} * " }]
Pry.config.ls.separator = "\n" # new lines between methods
Pry.config.ls.heading_color = :magenta
Pry.config.ls.public_method_color = :green
Pry.config.ls.protected_method_color = :yellow
Pry.config.ls.private_method_color = :bright_black
default_command_set = Pry::CommandSet.new do
command "copy", "Copy argument to the clip-board" do |str|
IO.popen('pbcopy', 'w') { |f| f << str.to_s }
end
command "clear" do
system 'clear'
if ENV['RAILS_ENV']
output.puts "Rails Environment: " + ENV['RAILS_ENV']
end
end
command "sql", "Send sql over AR." do |query|
if ENV['RAILS_ENV'] || defined?(Rails)
pp ActiveRecord::Base.connection.select_all(query)
else
pp "No rails env defined"
end
end
command "caller_method" do |depth|
depth = depth.to_i || 1
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ caller(depth+1).first
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
output.puts [file, line, method]
end
end
end
Pry.config.commands.import default_command_set
# Toys methods
# See https://gist.github.com/807492
class Array
def self.toy(n=10, &block)
block_given? ? Array.new(n,&block) : Array.new(n) {|i| i+1}
end
end
class Hash
def self.toy(n=10)
Hash[Array.toy(n).zip(Array.toy(n){|c| (96+(c+1)).chr})]
end
end
if defined?(Rails) && Rails.env
require 'logger'
require 'rails/console/app'
require 'rails/console/helpers'
include Rails::ConsoleMethods
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.clear_active_connections!
class Class
def core_ext
self.instance_methods.map {|m| [m, self.instance_method(m).source_location] }.select {|m| m[1] && m[1][0] =~/activesupport/}.map {|m| m[0]}.sort
end
end
end
if defined?(PryByebug)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end
# Hit Enter to repeat last command
Pry::Commands.command /^$/, "repeat last command" do
_pry_.run_command Pry.history.to_a.last
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment