Module: UtilityBelt::Equipper

Defined in:
lib/utility_belt/equipper.rb

Constant Summary collapse

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}

Class Method Summary collapse

Class Method Details

.equip(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/utility_belt/equipper.rb', line 26

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 = exceptions.to_s.to_a 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

      # Silently ignore unkown gadgets
      gadgets_to_equip << gadget if GADGETS.include? gadget
    end
  end

  gadgets_to_equip.each{|gadget| require "utility_belt/#{gadget}" }

  @equipped ||= true
end

.equipped?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/utility_belt/equipper.rb', line 66

def equipped?
  @equipped
end