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.1.8 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.7 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.6 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.5 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.4 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.3 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.2 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.1 lib/mountain-goat/switch_variant.rb
mountain-goat-0.1.0 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.20 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.19 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.18 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.17 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.16 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.15 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.14 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.13 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.12 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.11 lib/mountain-goat/switch_variant.rb
mountain-goat-0.0.10 lib/mountain-goat/switch_variant.rb