Class: SwitchChoice
- Inherits:
-
Object
- Object
- SwitchChoice
- Defined in:
- lib/mountain-goat/switch_choice.rb
Instance Method Summary collapse
-
#initialize(logger, test, chosen_choice) ⇒ SwitchChoice
constructor
A new instance of SwitchChoice.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(logger, test, chosen_choice) ⇒ SwitchChoice
Returns a new instance of SwitchChoice.
3 4 5 6 7 8 |
# File 'lib/mountain-goat/switch_choice.rb', line 3 def initialize(logger, test, chosen_choice) @chosen_choice = chosen_choice @test = test @logger = logger raise ArgumentError, "Test type must be switch-type" if !@test.is_switch end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mountain-goat/switch_choice.rb', line 10 def method_missing(sym, *args, &block) #priority = ( args.first || 1.0 ).to_f if @chosen_choice.nil? #If we have not chosen a choice, we are going to look through # each option and make sure we have a back-end entry in choices # for the type @logger.warn "Looking at option #{sym.to_s}" if @test.mg_choices.find( :first, :conditions => { :switch_type => sym.to_s } ).nil? @logger.warn "Creating switch-type choice #{sym.to_s}" @test.mg_choices.create!( :name => sym.to_s, :switch_type => sym.to_s, :value => nil ) end else if @chosen_choice.switch_type.to_s == sym.to_s @logger.warn "Executing option #{sym.to_s}" yield else @logger.warn "Bypassing option #{sym.to_s}" end end end |