Class: Rook::Recipe

Inherits:
Object
  • Object
show all
Includes:
Assertion
Defined in:
lib/rook/recipe.rb

Overview

recipe

ex.

hash = {
  'product'=>'hello.o',
  'ingreds'=>['hello.c'],
  'toppings'=>['hello.h'],
}

recipe1 = Recipe.new(hash) { gcc -o #{@product} #{@ingred} }
recipe1.invoke()

hash['method'] = 'sys "gcc -o #{@product} #{@ingred}"'
recipe2 = Recipe.new(hash)
recipe2.invoke()

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Assertion

#assert, #assert_failed

Constructor Details

#initialize(hash, &block) ⇒ Recipe

Returns a new instance of Recipe.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rook/recipe.rb', line 41

def initialize(hash, &block)
  @product  = hash['product']
  @product  = eval @product if @product.is_a?(String) && @product =~ /\A\/(.*)\/\z/
  @ingreds  = (hash['ingreds'] || []).flatten()
  @coprods  = (hash['coprods'] || []).flatten()
  @byprods  = (hash['byprods'] || []).flatten()
  @toppings = (hash['toppings'] || []).flatten()
  @params   = hash['params']
  @kind     = hash['kind'] || _detect_kind(@product)
  @method   = hash['method*']
  @block    = block || hash['block']
  @desc     = hash['desc'] || _default_desc(@product)
  @access   = hash['access'] || (@desc ? 'public' : 'private')
  @forced   = hash.key?('forced')   ? hash['forced']   : @product.is_a?(Symbol)
  @symbolic = hash.key?('symbolic') ? hash['symbolic'] : @product.is_a?(Symbol)
  @verbose  = hash['verbose']
  @fingerprint = hash['fingerprint']
  @bookname = hash['bookname']
  @linenum  = hash['linenum']    # start linenumber of method part
  @pattern  = _compile_pattern(@product) if @kind == 'generic'
end

Instance Attribute Details

#accessObject

Returns the value of attribute access.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def access
  @access
end

#blockObject

Returns the value of attribute block.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def block
  @block
end

#booknameObject

Returns the value of attribute bookname.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def bookname
  @bookname
end

#byprodsObject

Returns the value of attribute byprods.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def byprods
  @byprods
end

#coprodsObject

Returns the value of attribute coprods.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def coprods
  @coprods
end

#descObject

Returns the value of attribute desc.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def desc
  @desc
end

#fingerprintObject

Returns the value of attribute fingerprint.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def fingerprint
  @fingerprint
end

#forcedObject

Returns the value of attribute forced.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def forced
  @forced
end

#ingredsObject

Returns the value of attribute ingreds.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def ingreds
  @ingreds
end

#kindObject

Returns the value of attribute kind.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def kind
  @kind
end

#linenumObject

Returns the value of attribute linenum.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def linenum
  @linenum
end

#matchedObject

Returns the value of attribute matched.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def matched
  @matched
end

#methodObject Also known as: __method__

Returns the value of attribute method.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def method
  @method
end

#paramsObject

Returns the value of attribute params.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def params
  @params
end

#patternObject

Returns the value of attribute pattern.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def pattern
  @pattern
end

#productObject

Returns the value of attribute product.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def product
  @product
end

#symbolicObject

Returns the value of attribute symbolic.



63
64
65
# File 'lib/rook/recipe.rb', line 63

def symbolic
  @symbolic
end

#toppingsObject

Returns the value of attribute toppings.



62
63
64
# File 'lib/rook/recipe.rb', line 62

def toppings
  @toppings
end

#verboseObject

Returns the value of attribute verbose.



64
65
66
# File 'lib/rook/recipe.rb', line 64

def verbose
  @verbose
end

Instance Method Details

#all_ingredientsObject



114
115
116
117
118
119
# File 'lib/rook/recipe.rb', line 114

def all_ingredients
  list = []
  list.concat @ingreds if @ingreds
  list.concat @toppings if @toppings
  return list
end

#all_productsObject



106
107
108
109
110
111
# File 'lib/rook/recipe.rb', line 106

def all_products
  list = [ @product ]
  list.concat @coprods if @coprods
  list.concat @byprods if @byprods
  return list
end

#forced?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/rook/recipe.rb', line 91

def forced?
  return @forced
end

#invoke(kitchen) ⇒ Object



178
179
180
# File 'lib/rook/recipe.rb', line 178

def invoke(kitchen)
  Oven.new(self).bake(kitchen)
end

#match?(product) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/rook/recipe.rb', line 81

def match?(product)
  return (@pattern || @product) === product
end

#public?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/rook/recipe.rb', line 86

def public?
  return @access == 'public'
end

#symbolic?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/rook/recipe.rb', line 101

def symbolic?
  return @symbolic
end

#to_specific(product) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/rook/recipe.rb', line 162

def to_specific(product)
  return self unless @pattern
  matched = @pattern.match(product)
  matched  or raise RookError.new("product '#{product}' doesn't match to /#{@pattern.source}/")
  recipe = self.dup
  instance_variables.each do |var|
    val = Util.expand_matches(instance_variable_get(var), matched)
    recipe.instance_variable_set(var, val)
  end
  recipe.instance_variable_set('@product', product)
  recipe.kind = 'specific'
  recipe.matched = matched
  return recipe
end

#verbose?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/rook/recipe.rb', line 96

def verbose?
  return @verbose
end