Skip to content

Instantly share code, notes, and snippets.

@ascendbruce
Last active August 29, 2015 14:10
Show Gist options
  • Save ascendbruce/ccbfd0ea08a8ab976092 to your computer and use it in GitHub Desktop.
Save ascendbruce/ccbfd0ea08a8ab976092 to your computer and use it in GitHub Desktop.
rails console customization without modifying Gemfiles
# encoding: utf-8
# work-around from http://stackoverflow.com/a/15017892
required_version_gems = %w(
awesome_print-1.2.0
hirb-0.7.2
hirb-unicode-0.0.5
unicode-display_width-0.1.1
)
required_version_gems.each do |version_gem|
$LOAD_PATH << "/usr/local/opt/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/#{version_gem}/lib/"
end
# awesome print
begin
require "awesome_print"
# Use pry's formatter
# AwesomePrint.pry!
# Use Pry's formatter and pager (https://github.com/pry/pry/wiki/FAQ#how-can-i-use-awesome_print-with-pry)
Pry.config.print = proc { |output, value| Pry::Helpers::BaseHelpers.stagger_output("=> #{value.ai}", output) }
rescue LoadError => e
puts "[~/.pryrc] Load AwesomePrint failed: #{e.message}"
end
# hirb
begin
require "hirb"
require "hirb-unicode"
extend Hirb::Console
rescue LoadError => e
puts "[~/.pryrc] Load Hirb or related gems failed: #{e.message}"
end
# change prompt_name to rails project name if available
if defined? Rails
Pry.config.prompt_name = Rails.application.class.parent_name.underscore.dasherize
end
class Dev
def self.me
User.where(email: "[email protected]").first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment