forked from jferris/config_files
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added rails specific console for pry and irb
- Loading branch information
Showing
4 changed files
with
140 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# hirb: some nice stuff for Rails | ||
begin | ||
require 'hirb' | ||
HIRB_LOADED = true | ||
rescue LoadError | ||
HIRB_LOADED = false | ||
end | ||
|
||
require 'logger' | ||
|
||
def loud_logger | ||
enable_hirb | ||
set_logger_to Logger.new(STDOUT) | ||
end | ||
|
||
def quiet_logger | ||
disable_hirb | ||
set_logger_to nil | ||
end | ||
|
||
def set_logger_to(logger) | ||
ActiveRecord::Base.logger = logger | ||
ActiveRecord::Base.clear_reloadable_connections! | ||
end | ||
|
||
def enable_hirb | ||
if HIRB_LOADED | ||
Hirb::Formatter.dynamic_config['ActiveRecord::Base'] | ||
Hirb.enable | ||
else | ||
puts "hirb is not loaded" | ||
end | ||
end | ||
|
||
def disable_hirb | ||
if HIRB_LOADED | ||
Hirb.disable | ||
else | ||
puts "hirb is not loaded" | ||
end | ||
end | ||
|
||
def efind(email) | ||
User.find_by_email email | ||
end | ||
|
||
# set a nice prompt | ||
rails_root = File.basename(Dir.pwd) | ||
IRB.conf[:PROMPT] ||= {} | ||
IRB.conf[:PROMPT][:RAILS] = { | ||
:PROMPT_I => "#{rails_root}> ", # normal prompt | ||
:PROMPT_S => "#{rails_root}* ", # prompt when continuing a string | ||
:PROMPT_C => "#{rails_root}? ", # prompt when continuing a statement | ||
:RETURN => "=> %s\n" # prefixes output | ||
} | ||
IRB.conf[:PROMPT_MODE] = :RAILS | ||
|
||
# turn on the loud logging by default | ||
IRB.conf[:IRB_RC] = Proc.new { loud_logger } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,45 @@ | ||
# Pry config to work with RubyMine | ||
Pry.config.editor = proc { |file, line| "mine --line #{line} #{file}" } | ||
# Pry.config.editor = proc { |file, line| "mine --line #{line} #{file}" } | ||
Pry.config.editor = 'subl' | ||
|
||
begin | ||
require 'awesome_print' | ||
AwesomePrint.pry! | ||
rescue LoadError => err | ||
puts "no awesome_print :(" | ||
end | ||
|
||
|
||
# load .irbrc_rails in rails environments | ||
railsrc_path = File.expand_path('~/.pryrc_rails') | ||
if ( ENV['RAILS_ENV'] || defined? Rails ) && File.exist?( railsrc_path ) | ||
begin | ||
load railsrc_path | ||
rescue Exception | ||
warn "Could not load: #{ railsrc_path } because of #{$!.message}" | ||
end | ||
end | ||
|
||
# Easily print methods local to an object's class | ||
class Object | ||
def local_methods | ||
(methods - Object.instance_methods).sort | ||
end | ||
|
||
def interesting_methods | ||
case self.class | ||
when Class | ||
self.public_methods.sort - Object.public_methods | ||
when Module | ||
self.public_methods.sort - Module.public_methods | ||
else | ||
self.public_methods.sort - Object.new.public_methods | ||
end | ||
end | ||
end | ||
|
||
# copy a string to the clipboard | ||
def pbcopy(string) | ||
`echo "#{string}" | pbcopy` | ||
string | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# HIRB | ||
begin | ||
require 'hirb' | ||
rescue LoadError | ||
end | ||
|
||
|
||
if defined? Hirb | ||
# Slightly dirty hack to fully support in-session Hirb.disable/enable toggling | ||
Hirb::View.instance_eval do | ||
def enable_output_method | ||
@output_method = true | ||
@old_print = Pry.config.print | ||
Pry.config.print = proc do |output, value| | ||
Hirb::View.view_or_page_output(value) || @old_print.call(output, value) | ||
end | ||
end | ||
|
||
def disable_output_method | ||
Pry.config.print = @old_print | ||
@output_method = nil | ||
end | ||
end | ||
|
||
Hirb.enable | ||
end |