Class: Rook::Recipe
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
-
#access ⇒ Object
Returns the value of attribute access.
-
#block ⇒ Object
Returns the value of attribute block.
-
#bookname ⇒ Object
Returns the value of attribute bookname.
-
#byprods ⇒ Object
Returns the value of attribute byprods.
-
#coprods ⇒ Object
Returns the value of attribute coprods.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
-
#forced ⇒ Object
Returns the value of attribute forced.
-
#ingreds ⇒ Object
Returns the value of attribute ingreds.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#linenum ⇒ Object
Returns the value of attribute linenum.
-
#matched ⇒ Object
Returns the value of attribute matched.
-
#method ⇒ Object
(also: #__method__)
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#product ⇒ Object
Returns the value of attribute product.
-
#symbolic ⇒ Object
Returns the value of attribute symbolic.
-
#toppings ⇒ Object
Returns the value of attribute toppings.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #all_ingredients ⇒ Object
- #all_products ⇒ Object
- #forced? ⇒ Boolean
-
#initialize(hash, &block) ⇒ Recipe
constructor
A new instance of Recipe.
- #invoke(kitchen) ⇒ Object
- #match?(product) ⇒ Boolean
- #public? ⇒ Boolean
- #symbolic? ⇒ Boolean
- #to_specific(product) ⇒ Object
- #verbose? ⇒ Boolean
Methods included from Assertion
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
#access ⇒ Object
Returns the value of attribute access.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def access @access end |
#block ⇒ Object
Returns the value of attribute block.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def block @block end |
#bookname ⇒ Object
Returns the value of attribute bookname.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def bookname @bookname end |
#byprods ⇒ Object
Returns the value of attribute byprods.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def byprods @byprods end |
#coprods ⇒ Object
Returns the value of attribute coprods.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def coprods @coprods end |
#desc ⇒ Object
Returns the value of attribute desc.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def desc @desc end |
#fingerprint ⇒ Object
Returns the value of attribute fingerprint.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def fingerprint @fingerprint end |
#forced ⇒ Object
Returns the value of attribute forced.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def forced @forced end |
#ingreds ⇒ Object
Returns the value of attribute ingreds.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def ingreds @ingreds end |
#kind ⇒ Object
Returns the value of attribute kind.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def kind @kind end |
#linenum ⇒ Object
Returns the value of attribute linenum.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def linenum @linenum end |
#matched ⇒ Object
Returns the value of attribute matched.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def matched @matched end |
#method ⇒ Object Also known as: __method__
Returns the value of attribute method.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def params @params end |
#pattern ⇒ Object
Returns the value of attribute pattern.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def pattern @pattern end |
#product ⇒ Object
Returns the value of attribute product.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def product @product end |
#symbolic ⇒ Object
Returns the value of attribute symbolic.
63 64 65 |
# File 'lib/rook/recipe.rb', line 63 def symbolic @symbolic end |
#toppings ⇒ Object
Returns the value of attribute toppings.
62 63 64 |
# File 'lib/rook/recipe.rb', line 62 def toppings @toppings end |
#verbose ⇒ Object
Returns the value of attribute verbose.
64 65 66 |
# File 'lib/rook/recipe.rb', line 64 def verbose @verbose end |
Instance Method Details
#all_ingredients ⇒ Object
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_products ⇒ Object
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
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
81 82 83 |
# File 'lib/rook/recipe.rb', line 81 def match?(product) return (@pattern || @product) === product end |
#public? ⇒ Boolean
86 87 88 |
# File 'lib/rook/recipe.rb', line 86 def public? return @access == 'public' end |
#symbolic? ⇒ 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.(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
96 97 98 |
# File 'lib/rook/recipe.rb', line 96 def verbose? return @verbose end |