Created
January 15, 2014 20:29
-
-
Save jbailey/8443915 to your computer and use it in GitHub Desktop.
My .irbrc and .railsrc files.
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
#!/usr/bin/ruby | |
# Add all gems installed in the system to the $LOAD_PATH so they can be used in Rails console with Bundler | |
if defined?(::Bundler) | |
current_ruby_version = `rbenv version`.split(" ").first | |
gem_paths = Dir.glob("#{ENV["HOME"]}/.rbenv/versions/#{current_ruby_version}/lib/ruby/gems/**/gems/*/lib") | |
gem_paths.each do |path| | |
$LOAD_PATH << path | |
end | |
end | |
require 'irb/completion' | |
require 'irb/ext/save-history' | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb_history" | |
IRB.conf[:PROMPT_MODE] = :SIMPLE | |
%w[rubygems looksee wirble pp map_by_method what_methods].each do |gem| | |
begin | |
require gem | |
rescue LoadError | |
puts "Failed to load #{gem}" | |
end | |
end | |
# Wirble settings | |
begin | |
Wirble.init | |
%w{init colorize}.each { |str| Wirble.send(str) } | |
rescue | |
puts "Wirble unavailable" | |
end | |
class Object | |
# list methods which aren't in superclass | |
def local_methods(obj = self) | |
(obj.methods - obj.class.superclass.instance_methods).sort | |
end | |
# print documentation | |
# | |
# ri 'Array#pop' | |
# Array.ri | |
# Array.ri :pop | |
# arr.ri :pop | |
def ri(method = nil) | |
unless method && method =~ /^[A-Z]/ # if class isn't specified | |
klass = self.kind_of?(Class) ? name : self.class.name | |
method = [klass, method].compact.join('#') | |
end | |
system 'ri', method.to_s | |
end | |
end | |
def copy(str) | |
IO.popen('pbcopy', 'w') { |f| f << str.to_s } | |
end | |
def copy_history | |
history = Readline::HISTORY.entries | |
index = history.rindex("exit") || -1 | |
content = history[(index+1)..-2].join("\n") | |
puts content | |
copy content | |
end | |
def paste | |
`pbpaste` | |
end | |
railsrc_path = File.expand_path('~/.railsrc') | |
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 | |
# Break out of the Bundler jail | |
if defined? Bundler | |
Gem.post_reset_hooks.reject! { |hook| hook.source_location.first =~ %r{/bundler/} } | |
Gem::Specification.reset | |
load 'rubygems/custom_require.rb' | |
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
#!/usr/bin/ruby | |
begin | |
require 'hirb' # sudo gem install cldwalker-hirb --source http://gems.github.com | |
Hirb.disable | |
rescue LoadError | |
end | |
def sql(query) | |
ActiveRecord::Base.connection.select_all(query) | |
end | |
def change_log(stream) | |
ActiveRecord::Base.logger = Logger.new(stream) | |
ActiveRecord::Base.clear_active_connections! | |
end | |
def show_log | |
change_log(STDOUT) | |
true | |
end | |
def hide_log | |
change_log(nil) | |
true | |
end | |
hide_log # Start hidden | |
def load_lib | |
path = File.join( Rails.root, 'lib') | |
failures = [] | |
Dir.glob("#{path}/**/*.rb").each { |file| | |
#puts "loading: #{file} ... " | |
begin | |
load file | |
rescue => ex | |
failures << file | |
end | |
} | |
# this second pass is here to try to catch anything that | |
# is dependent on something else | |
# could be improved, but is working fine for my needs | |
double_failures = [] | |
for file in failures | |
begin | |
load file | |
rescue => ex1 | |
double_failures << file | |
end | |
end | |
if double_failures.size > 0 | |
puts "these files failed twice" | |
for file in double_failures | |
puts file | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment