Class: Fakes::ClassSwaps

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fakes/class_swaps.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClassSwaps

Returns a new instance of ClassSwaps.



8
9
10
# File 'lib/fakes/class_swaps.rb', line 8

def initialize
  @swaps = {}
end

Instance Attribute Details

#swapsObject (readonly)

Returns the value of attribute swaps.



6
7
8
# File 'lib/fakes/class_swaps.rb', line 6

def swaps
  @swaps
end

Instance Method Details

#add_fake_for(klass, the_fake) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/fakes/class_swaps.rb', line 12

def add_fake_for(klass,the_fake)
  symbol = klass.to_s.to_sym
  ensure_swap_does_not_already_exist_for(symbol)
  swap = ClassSwap.new(klass,the_fake)
  @swaps[symbol] = swap
  swap.initiate
end

#ensure_swap_does_not_already_exist_for(symbol) ⇒ Object



20
21
22
# File 'lib/fakes/class_swaps.rb', line 20

def ensure_swap_does_not_already_exist_for(symbol)
  raise "A swap already exists for the class #{symbol}" if @swaps.has_key?(symbol)
end

#resetObject



24
25
26
27
# File 'lib/fakes/class_swaps.rb', line 24

def reset
  @swaps.values.each{|item| item.reset}
  @swaps.clear
end