Skip to content

Instantly share code, notes, and snippets.

@jackdempsey
Created September 13, 2010 18:19
Show Gist options
  • Save jackdempsey/577755 to your computer and use it in GitHub Desktop.
Save jackdempsey/577755 to your computer and use it in GitHub Desktop.
git/jackdempsey.github.com master > gem uninstall flyrb
Remove executables:
amazon, google, pastie
in addition to the gem? [Yn] y
Removing amazon
Removing google
Removing pastie
Successfully uninstalled flyrb-1.0.0.b
git/jackdempsey.github.com master > gi flyrb --pre
Successfully installed flyrb-1.0.0.b
1 gem installed
git/jackdempsey.github.com master > cat ~/.rvm/gems/ruby-1.9.2-p0/gems/flyrb-1.0.0.b/lib/flyrb/equipper.rb
# Allow to select which gadgets to equip
#
# Author: Markus Prinz <[email protected]>
module Flyrb
class << self
def equip(*args)
Equipper.equip(*args)
end
def equipped?
Equipper.equipped?
end
end
module Equipper
GADGETS = Dir[File.join(File.dirname(__FILE__), '*.rb')].map{|file| File.basename(file)[0..-4]}.reject{|gadget| "equipper" == gadget }
DEFAULTS = %w{wirble
hash_math
interactive_editor
irb_options
irb_verbosity_control}
@equipped = false
class << self
def equip(*args)
return if args.empty?
gadgets_to_equip = []
# Special case using :all or :none
if args[0].is_a?(Symbol) && [:all, :none, :defaults].include?(args[0])
what = args[0]
unless args[1].nil?
exceptions = args[1].has_key?(:except) ? args[1][:except] : []
# Handle special case where we get a string or a symbol instead of an array
exceptions = Array(exceptions.to_s) unless exceptions.is_a?( Array )
else
exceptions = []
end
case what
when :all
gadgets_to_equip.push(*(GADGETS - exceptions))
when :none
gadgets_to_equip.push(*exceptions)
when :defaults
gadgets_to_equip.push(*DEFAULTS)
end
# otherwise, args is a list of gadgets to equip
else
args.each do |arg|
gadget = arg.to_s
if GADGETS.include? gadget
gadgets_to_equip << gadget
else
# Don't silently ignore unkown gadgets
puts "Failed to find gadget #{gadget}, ignoring"
end
end
end
gadgets_to_equip.each{|gadget|
puts "enabling #{gadget}"
require "flyrb/#{gadget}"
}
@equipped ||= true
end
def equipped?
@equipped
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment