Sha256: 53bce9b4b8d369c46b51883a981f22537060b41a588e27ff206c1b463565f426

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

module Fiveruns::Dash
  
  class Recipe
    
    class ConfigurationError < ::ArgumentError; end
    
    def self.scope_stack
      @scope_stack ||= []
    end
    
    def self.current
      scope_stack.last
    end
    
    def self.in_scope(recipe)
      scope_stack << recipe
      yield
      scope_stack.pop
    end
    
    attr_reader :name, :url, :options
    def initialize(name, options = {}, &block)
      @name = name
      @options = options
      @url = options[:url]
      @block = block
      validate!
    end
    
    def add_to(configuration)
      self.class.in_scope(self) do
        @block.call(configuration)
      end
    end
    
    # Currently :url is the only criteria; all other parts
    # of the hash are settings to be passed on to the recipe
    def matches?(criteria)
      criteria.all? do |k, v|
        if [:url].include?(k)
          options[k] == v
        else
          true
        end
      end
    end
    
    def ==(other)
      name == other.name && other.options == options
    end
    
    def info
      {
        :name => name.to_s,
        :url => url.to_s
      }
    end
        
    #######
    private
    #######

    def validate!
      unless @url
        raise ConfigurationError, "Recipe requires :url option"
      end
    end
    
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fiveruns-dash-ruby-0.8.1 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.10 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.3 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.4 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.5 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.6 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.8 lib/fiveruns/dash/recipe.rb
fiveruns-dash-ruby-0.8.9 lib/fiveruns/dash/recipe.rb