Sha256: 0ec23a45550f4e27e0d0cf0a4c42ba678586ce198eaa465a68c9aad5ad52c1aa

Contents?: true

Size: 1.19 KB

Versions: 28

Compression:

Stored size: 1.19 KB

Contents

class SwitchVariant    
    def initialize(logger, metric, convert, chosen_variant)
      @chosen_variant = chosen_variant  
      @metric, @convert = metric, convert
      @logger = logger
      raise ArgumentError, "Metric type must be switch-type" if !@metric.is_switch
    end
    
    def method_missing(sym, *args, &block)
      priority = ( args.first || 1.0 ).to_f
      
      if @chosen_variant.nil?
        #If we have not chosen a variant, we are going to look through
        # each option and make sure we have a back-end entry in metric_variants
        # for the type
        @logger.warn "Looking at option #{sym.to_s}"
        if @metric.metric_variants.find( :first, :conditions => { :switch_type => sym.to_s } ).nil?
          @logger.warn "Creating switch-type metric-variant #{sym.to_s}"
          @metric.metric_variants.create!( :name => sym.to_s, :switch_type => sym.to_s, :priority => priority, :value => nil )
        end
      else
        if @chosen_variant.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
  
  end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mountain-goat-0.0.9 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.8 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.6 lib/mountain_goat/switch_variant.rb
mountain-goat-0.0.5 lib/mountain_goat/switch_variant.rb
mountain-goat-0.0.4 lib/mountain_goat/switch_variant.rb
mountain-goat-0.0.3 lib/mountain_goat/switch_variant.rb
mountain-goat-0.0.2 lib/mountain_goat/switch_variant.rb
mountain-goat-0.0.1 lib/mountain_goat/switch_variant.rb