Class: Fiveruns::Dash::Recipe

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/dash/recipe.rb

Defined Under Namespace

Classes: ConfigurationError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Recipe

Returns a new instance of Recipe.



22
23
24
25
26
27
28
# File 'lib/fiveruns/dash/recipe.rb', line 22

def initialize(name, options = {}, &block)
  @name = name
  @options = options
  @url = options[:url]
  @block = block
  validate!
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/fiveruns/dash/recipe.rb', line 21

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



21
22
23
# File 'lib/fiveruns/dash/recipe.rb', line 21

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url.



21
22
23
# File 'lib/fiveruns/dash/recipe.rb', line 21

def url
  @url
end

Class Method Details

.currentObject



11
12
13
# File 'lib/fiveruns/dash/recipe.rb', line 11

def self.current
  scope_stack.last
end

.in_scope(recipe) ⇒ Object



15
16
17
18
19
# File 'lib/fiveruns/dash/recipe.rb', line 15

def self.in_scope(recipe)
  scope_stack << recipe
  yield
  scope_stack.pop
end

.scope_stackObject



7
8
9
# File 'lib/fiveruns/dash/recipe.rb', line 7

def self.scope_stack
  @scope_stack ||= []
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/fiveruns/dash/recipe.rb', line 48

def ==(other)
  name == other.name && other.options == options
end

#add_to(configuration) ⇒ Object



30
31
32
33
34
# File 'lib/fiveruns/dash/recipe.rb', line 30

def add_to(configuration)
  self.class.in_scope(self) do
    @block.call(configuration)
  end
end

#infoObject



52
53
54
55
56
57
# File 'lib/fiveruns/dash/recipe.rb', line 52

def info
  {
    :name => name.to_s,
    :url => url.to_s
  }
end

#matches?(criteria) ⇒ Boolean

Currently :url is the only criteria; all other parts of the hash are settings to be passed on to the recipe

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
# File 'lib/fiveruns/dash/recipe.rb', line 38

def matches?(criteria)
  criteria.all? do |k, v|
    if [:url].include?(k)
      options[k] == v
    else
      true
    end
  end
end