rook 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LGPL +504 -0
- data/README.txt +15 -6
- data/bin/rook +1 -1
- data/doc-api/classes/BZ2/Reader.html +24 -24
- data/doc-api/classes/Digest/Base.html +18 -18
- data/doc-api/classes/Enumerable.html +55 -55
- data/doc-api/classes/File.html +53 -6
- data/doc-api/classes/FileUtils.html +90 -90
- data/doc-api/classes/Kernel.html +48 -48
- data/doc-api/classes/Rook.html +18 -5
- data/doc-api/classes/Rook/Assertion.html +29 -14
- data/doc-api/classes/Rook/Commands.html +296 -364
- data/doc-api/classes/Rook/Cookbook.html +165 -60
- data/doc-api/classes/Rook/CookbookError.html +7 -7
- data/doc-api/classes/Rook/CookbookValidator.html +24 -24
- data/doc-api/classes/Rook/Kitchen.html +379 -224
- data/doc-api/classes/Rook/KitchenHelper.html +69 -69
- data/doc-api/classes/Rook/Main.html +47 -30
- data/doc-api/classes/Rook/Recipe.html +63 -35
- data/doc-api/classes/Rook/Util.html +72 -68
- data/doc-api/classes/Rook/Util/UndefinedPropertyError.html +6 -6
- data/doc-api/classes/Rook/{Parameters.html → ValueTable.html} +129 -123
- data/doc-api/created.rid +1 -1
- data/doc-api/files/rook/commands_rb.html +2 -2
- data/doc-api/files/rook/cookbook_rb.html +2 -2
- data/doc-api/files/rook/helper/bz2_rb.html +1 -1
- data/doc-api/files/rook/helper/digest_rb.html +1 -1
- data/doc-api/files/rook/helper/enumerable_rb.html +1 -1
- data/doc-api/files/rook/helper/file_rb.html +2 -2
- data/doc-api/files/rook/helper/fileutils_rb.html +1 -1
- data/doc-api/files/rook/helper/kernel_rb.html +1 -1
- data/doc-api/files/rook/kitchen_rb.html +2 -2
- data/doc-api/files/rook/main_rb.html +2 -2
- data/doc-api/files/rook/recipe_rb.html +2 -2
- data/doc-api/files/rook/util_rb.html +2 -2
- data/doc-api/files/rook_rb.html +2 -2
- data/doc-api/fr_class_index.html +1 -1
- data/doc-api/fr_file_index.html +0 -1
- data/doc-api/fr_method_index.html +148 -140
- data/doc-api/index.html +1 -1
- data/examples/hello_c/Rookbook.rb +1 -1
- data/examples/hello_c/Rookbook.yaml +8 -8
- data/examples/project/README.txt +2 -2
- data/examples/project/Rookbook.rb +20 -19
- data/examples/project/Rookbook.yaml +30 -28
- data/examples/project/bin/example +2 -2
- data/examples/project/example.gemspec +1 -1
- data/examples/project/lib/example.rb +2 -2
- data/examples/project/test/test.rb +2 -2
- data/lib/rook.rb +5 -2
- data/lib/rook/commands.rb +28 -17
- data/lib/rook/cookbook.rb +107 -92
- data/lib/rook/helper/bz2.rb +1 -1
- data/lib/rook/helper/digest.rb +1 -1
- data/lib/rook/helper/enumerable.rb +1 -1
- data/lib/rook/helper/file.rb +28 -3
- data/lib/rook/helper/fileutils.rb +1 -1
- data/lib/rook/helper/kernel.rb +1 -1
- data/lib/rook/kitchen.rb +138 -100
- data/lib/rook/main.rb +72 -47
- data/lib/rook/recipe.rb +51 -35
- data/lib/rook/rookbook.schema.yaml +34 -54
- data/lib/rook/util.rb +22 -8
- data/rook.gemspec +5 -5
- metadata +5 -7
- data/COPYING +0 -340
- data/doc-api/files/__/README_txt.html +0 -313
data/lib/rook/cookbook.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 0.
|
2
|
+
## $Rev: 36 $
|
3
|
+
## $Release: 0.2.0 $
|
4
4
|
## copyright(c) 2006 kuwata-lab.com all rights reserved.
|
5
5
|
##
|
6
6
|
|
@@ -15,6 +15,19 @@ module Rook
|
|
15
15
|
|
16
16
|
|
17
17
|
|
18
|
+
class CookbookError < RookError
|
19
|
+
|
20
|
+
|
21
|
+
def initialize(message, validation_errors)
|
22
|
+
@errors = validation_errors
|
23
|
+
end
|
24
|
+
attr_reader :errors
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
18
31
|
class CookbookValidator < Kwalify::Validator
|
19
32
|
|
20
33
|
|
@@ -52,9 +65,9 @@ module Rook
|
|
52
65
|
when 'PROP'
|
53
66
|
value.each do |k, v|
|
54
67
|
if !k.is_a?(String)
|
55
|
-
errors <<
|
56
|
-
elsif k !~ /\A[a-zA-Z_]
|
57
|
-
errors <<
|
68
|
+
errors << create_error("#{path}/#{k}", "property name is not a string.")
|
69
|
+
elsif k !~ /\A[a-zA-Z_]\w*\*?\z/ && k != '.desc'
|
70
|
+
errors << create_error("#{path}/#{k}", "invlaid property name.")
|
58
71
|
elsif k[-1] == ?* && !v.is_a?(String)
|
59
72
|
errors << create_error("#{path}/#{k}", "expr is not a string.")
|
60
73
|
end
|
@@ -67,19 +80,6 @@ module Rook
|
|
67
80
|
|
68
81
|
|
69
82
|
|
70
|
-
class CookbookError < RookError
|
71
|
-
|
72
|
-
|
73
|
-
def initialize(message, validation_errors)
|
74
|
-
@errors = validation_errors
|
75
|
-
end
|
76
|
-
attr_reader :errors
|
77
|
-
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
83
|
##
|
84
84
|
## represents cookbook
|
85
85
|
##
|
@@ -99,20 +99,20 @@ module Rook
|
|
99
99
|
|
100
100
|
##
|
101
101
|
def initialize(bookname=nil, load_yaml=true, expand_tab=true)
|
102
|
-
@
|
102
|
+
@preparations = []
|
103
103
|
@properties = []
|
104
|
-
@
|
104
|
+
@parameters = []
|
105
105
|
@materials = []
|
106
106
|
@recipes = []
|
107
107
|
@bookname = bookname
|
108
108
|
load_yamlfile(bookname, expand_tab) if bookname && load_yaml
|
109
109
|
end
|
110
|
-
attr_reader :properties, :
|
110
|
+
attr_reader :properties, :parameters, :recipes, :materials, :preparations
|
111
111
|
attr_accessor :bookname
|
112
112
|
|
113
113
|
|
114
|
-
def
|
115
|
-
return @
|
114
|
+
def preparation
|
115
|
+
return @preparations.map { |hash| hash['code'] }.join("\n")
|
116
116
|
end
|
117
117
|
|
118
118
|
|
@@ -143,91 +143,106 @@ module Rook
|
|
143
143
|
|
144
144
|
def load_ydoc(ydoc, parser=nil)
|
145
145
|
ydoc = ydoc.dup
|
146
|
-
#
|
147
|
-
code = ydoc['
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
ydoc[
|
146
|
+
# preparation
|
147
|
+
if code = ydoc['preparation*']
|
148
|
+
linenum = parser.path_linenum('/preparation*')
|
149
|
+
@preparations << { 'code'=>code, 'linenum'=>linenum+1 }
|
150
|
+
end
|
151
|
+
# properties, parameters
|
152
|
+
[ 'properties', 'parameters' ].each do |part|
|
153
|
+
next unless ydoc[part]
|
154
|
+
list = part == 'properties' ? @properties : @parameters
|
155
|
+
ydoc[part].each_with_index do |prop, i|
|
154
156
|
opts = {}
|
155
157
|
prop.keys.each do |k| opts[k.to_s] = prop[k] if k.is_a?(Symbol) end
|
156
158
|
prop.each do |name, val|
|
157
159
|
next unless name.is_a?(String)
|
158
|
-
|
160
|
+
linenum = parser.path_linenum("/#{part}/#{i}/#{name}")
|
161
|
+
vkey = name[-1] == ?* ? 'value*' : 'value'
|
159
162
|
#name[-1,1] = '' if name[-1] == ?* # TypeError: can't modify frozen string
|
160
163
|
name = name[0, name.length-1] if name[-1] == ?*
|
161
|
-
h = { 'name'=>name, vkey=>val }
|
164
|
+
h = { 'name'=>name, vkey=>val, 'linenum'=>linenum }
|
162
165
|
h.update(opts)
|
163
166
|
list << h
|
164
167
|
end
|
165
168
|
end
|
166
|
-
ydoc[key] = list
|
167
169
|
end
|
170
|
+
# materials
|
171
|
+
if list = ydoc['materials']
|
172
|
+
@materials += list
|
173
|
+
end
|
174
|
+
# recipes
|
175
|
+
if list = ydoc['recipes']
|
176
|
+
list.each_with_index do |hash, i|
|
177
|
+
if hash['method*']
|
178
|
+
linenum = parser.path_linenum("/recipes/#{i}/method*")
|
179
|
+
hash['linenum'] = linenum+1
|
180
|
+
end
|
181
|
+
if hash['params']
|
182
|
+
list = []
|
183
|
+
hash['params'].each_with_index do |params, n|
|
184
|
+
params.each do |name, val|
|
185
|
+
linenum = parser.path_linenum("/recipes/#{i}/params/#{n}/#{name}")
|
186
|
+
list << { 'name'=>name, 'value'=>val, 'linenum'=>linenum }
|
187
|
+
end
|
188
|
+
end
|
189
|
+
hash['params'] = list
|
190
|
+
end
|
191
|
+
@recipes << hash
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
def validate_rubycode
|
198
|
+
lines = []
|
199
|
+
@preparations.each do |hash|
|
200
|
+
_add_code(lines, hash, 'code')
|
201
|
+
end if @preparations
|
202
|
+
@properties.each do |hash|
|
203
|
+
_add_code(lines, hash, 'value*') if hash.key?('value*')
|
204
|
+
end if @properties
|
205
|
+
@parameters.each do |hash|
|
206
|
+
_add_code(lines, hash, 'value*') if hash.key?('value*')
|
207
|
+
end if @parameters
|
208
|
+
@recipes.each do |hash|
|
209
|
+
_add_code(lines, hash, 'method*') if hash.key?('method*')
|
210
|
+
hash['params'].each do |h|
|
211
|
+
name = h['name']
|
212
|
+
_add_code(lines, h, 'value') if name[-1] == ?*
|
213
|
+
end if hash.key?('params')
|
214
|
+
end if @recipes
|
168
215
|
#
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
216
|
+
lines.shift # ignore first item
|
217
|
+
code = ''
|
218
|
+
lines.each do |line|
|
219
|
+
code << (line || "") << "\n"
|
220
|
+
end
|
221
|
+
tmpfilename = "#{@bookname}." # or user tmpfile library
|
222
|
+
begin
|
223
|
+
File.open(tmpfilename, 'w') { |f| f.write(code) }
|
224
|
+
#case RUBY_PLATFORM
|
225
|
+
#when /linux/, /bsd/, /darwin/, /cygwin/
|
226
|
+
out = `ruby -wc #{tmpfilename} 2>&1`
|
227
|
+
puts out.gsub(/^#{tmpfilename}/, bookname)
|
228
|
+
#else
|
229
|
+
# system "ruby -wc #{tmpfilename}"
|
230
|
+
#end
|
231
|
+
ensure
|
232
|
+
File.unlink(tmpfilename) if test(?f, tmpfilename)
|
233
|
+
end
|
234
|
+
|
178
235
|
end
|
179
236
|
|
180
237
|
|
181
|
-
def
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
list << hash
|
189
|
-
end if section
|
190
|
-
return list
|
238
|
+
def _add_code(lines, hash, key)
|
239
|
+
if hash.key?(key)
|
240
|
+
code = hash[key]
|
241
|
+
n = hash['linenum'] - 1
|
242
|
+
code.each_line { |line| lines[n += 1] = line.chomp }
|
243
|
+
lines[n] = lines[n] + ';'
|
244
|
+
end
|
191
245
|
end
|
192
|
-
private :_load_section
|
193
|
-
|
194
|
-
|
195
|
-
#--
|
196
|
-
#def load_dsl(ruby_code)
|
197
|
-
# eval(ruby_code, binding(), @bookname, 1)
|
198
|
-
#end
|
199
|
-
#++
|
200
|
-
|
201
|
-
|
202
|
-
#--
|
203
|
-
#def self.load_yamlfile(bookname, tab_expand=true)
|
204
|
-
# str = File.read(bookname)
|
205
|
-
# str = Util.untabify(str) if tab_expand
|
206
|
-
# return load_yamlstr(str, bookname)
|
207
|
-
#end
|
208
|
-
#
|
209
|
-
#
|
210
|
-
#def self.load_yamlstr(yaml_str, bookname)
|
211
|
-
# parser = Kwalify::YamlParser.new(yaml_str)
|
212
|
-
# ydocs = []
|
213
|
-
# errors = []
|
214
|
-
# books = []
|
215
|
-
# while parser.has_next?
|
216
|
-
# ydoc = parser.parse()
|
217
|
-
# errs = @@validator.validate(ydoc)
|
218
|
-
# if errs && !errs.empty?
|
219
|
-
# errors += errs
|
220
|
-
# else
|
221
|
-
# cookbook = self.new
|
222
|
-
# cookbook.bookname = bookname
|
223
|
-
# cookbook.load_ydoc(ydoc, parser)
|
224
|
-
# books << cookbook
|
225
|
-
# end
|
226
|
-
# end
|
227
|
-
# errors.empty? or raise CookbookError.new("invalid cookbook", errors)
|
228
|
-
# return books
|
229
|
-
#end
|
230
|
-
#++
|
231
246
|
|
232
247
|
|
233
248
|
end
|
data/lib/rook/helper/bz2.rb
CHANGED
data/lib/rook/helper/digest.rb
CHANGED
data/lib/rook/helper/file.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 0.
|
2
|
+
## $Rev: 37 $
|
3
|
+
## $Release: 0.2.0 $
|
4
4
|
## copyright(c) 2006 kuwata-lab.com all rights reserved.
|
5
5
|
##
|
6
6
|
|
@@ -18,20 +18,45 @@ class File
|
|
18
18
|
## File.edit('file.txt') do |content|
|
19
19
|
## content.gsub!(/\$Release\$/, '1.0.0')
|
20
20
|
## content.gsub!(/\$Copyright\$/, '(c)kuwata-lab')
|
21
|
+
## content
|
21
22
|
## end
|
22
23
|
##
|
23
24
|
def self.edit(filename, &block)
|
24
25
|
File.open(filename, 'r+') do |f|
|
25
26
|
content = f.read()
|
26
27
|
#yield(content)
|
27
|
-
block.arity == 1 ? yield(content) : yield(content, filename)
|
28
|
+
result = block.arity == 1 ? yield(content) : yield(content, filename)
|
28
29
|
f.rewind()
|
29
30
|
f.truncate(0)
|
31
|
+
#f.write(result)
|
30
32
|
f.write(content)
|
31
33
|
end if test(?f, filename)
|
32
34
|
end
|
33
35
|
|
34
36
|
|
37
|
+
##
|
38
|
+
## replace file content with the result of block.
|
39
|
+
##
|
40
|
+
## ex.
|
41
|
+
## File.replace('file.txt') do |content|
|
42
|
+
## s = content
|
43
|
+
## s = s.gsub(/\$Release\$/, '1.0.0')
|
44
|
+
## s = s.gsub(/\$Copyright\$/, '(c)kuwata-lab')
|
45
|
+
## s
|
46
|
+
## end
|
47
|
+
##
|
48
|
+
def self.replace(filename, &block)
|
49
|
+
File.open(filename, 'r+') do |f|
|
50
|
+
content = f.read()
|
51
|
+
#yield(content)
|
52
|
+
s = block.arity == 1 ? yield(content) : yield(content, filename)
|
53
|
+
f.rewind()
|
54
|
+
f.truncate(0)
|
55
|
+
f.write(s)
|
56
|
+
end if test(?f, filename)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
35
60
|
##
|
36
61
|
## write file
|
37
62
|
##
|
data/lib/rook/helper/kernel.rb
CHANGED
data/lib/rook/kitchen.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
##
|
2
|
-
## $Rev:
|
3
|
-
## $Release: 0.
|
2
|
+
## $Rev: 35 $
|
3
|
+
## $Release: 0.2.0 $
|
4
4
|
## copyright(c) 2006 kuwata-lab.com all rights reserved.
|
5
5
|
##
|
6
6
|
|
@@ -52,36 +52,36 @@ module Rook
|
|
52
52
|
end
|
53
53
|
|
54
54
|
#--
|
55
|
-
#abstract_method 'hash', :add_property, :
|
55
|
+
#abstract_method 'hash', :add_property, :add_parameter
|
56
56
|
#++
|
57
57
|
|
58
58
|
def add_property(hash)
|
59
59
|
not_implemented
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def add_parameter(hash)
|
63
63
|
not_implemented
|
64
64
|
end
|
65
65
|
|
66
66
|
|
67
67
|
##
|
68
|
-
## define a
|
68
|
+
## define a parameter in Rookbook.rb
|
69
69
|
##
|
70
70
|
## ex. (in Rookbook.rb)
|
71
|
-
##
|
72
|
-
##
|
73
|
-
##
|
71
|
+
## parameter :srcdir, 'src'
|
72
|
+
## parameter :files, Dir.glob('src/*.rb')
|
73
|
+
## parameter :rook_product, :all
|
74
74
|
##
|
75
75
|
## the above code is equivalent to the following in Rookbook.yaml:
|
76
|
-
##
|
76
|
+
## parameters:
|
77
77
|
## - srcdir : src
|
78
78
|
## - files* : Dir.glob('src/*.rb')
|
79
79
|
## - rook_product : :all
|
80
80
|
##
|
81
|
-
def
|
81
|
+
def parameter(name, value, options={}) # :doc:
|
82
82
|
hash = { 'name'=>name.to_s, 'value'=>value }
|
83
83
|
options.each { |name, value| hash[name.to_s] = value }
|
84
|
-
|
84
|
+
add_parameter(hash)
|
85
85
|
end
|
86
86
|
|
87
87
|
|
@@ -139,7 +139,7 @@ module Rook
|
|
139
139
|
## define a recipe in Rookbook.rb
|
140
140
|
##
|
141
141
|
## ex. (in Rookbook.rb)
|
142
|
-
## recipe '*.o' , '$(1).c', :
|
142
|
+
## recipe '*.o' , '$(1).c', :toppings=>['$(1).h'], :desc=>'compile *.c' do
|
143
143
|
## sys "gcc -c #{@ingreds[0]}"
|
144
144
|
## end
|
145
145
|
##
|
@@ -147,7 +147,7 @@ module Rook
|
|
147
147
|
## recipes:
|
148
148
|
## - product: *.o
|
149
149
|
## ingreds: [ $(1).c ]
|
150
|
-
##
|
150
|
+
## toppings: [ $(1).h ]
|
151
151
|
## desc: compile *.c
|
152
152
|
## method: |
|
153
153
|
## sys "gcc -c #{@ingreds[0]}"
|
@@ -191,19 +191,19 @@ module Rook
|
|
191
191
|
end
|
192
192
|
|
193
193
|
|
194
|
-
class
|
194
|
+
class ValueTable
|
195
195
|
|
196
196
|
def initialize
|
197
197
|
@_property_table = {}
|
198
|
-
@
|
198
|
+
@_parameter_table = {}
|
199
199
|
end
|
200
200
|
|
201
201
|
def has_property?(name)
|
202
202
|
return @_property_table.key?(name.to_s)
|
203
203
|
end
|
204
204
|
|
205
|
-
def
|
206
|
-
return @
|
205
|
+
def has_parameter?(name)
|
206
|
+
return @_parameter_table.key?(name.to_s)
|
207
207
|
end
|
208
208
|
|
209
209
|
def set_property(name, value)
|
@@ -213,44 +213,50 @@ module Rook
|
|
213
213
|
instance_variable_set("@#{name}", value)
|
214
214
|
end
|
215
215
|
|
216
|
-
def
|
217
|
-
@
|
216
|
+
def set_parameter(name, value)
|
217
|
+
@_parameter_table[name.to_s] = value
|
218
218
|
end
|
219
219
|
|
220
220
|
def get_property(name)
|
221
221
|
return @_property_table[name.to_s]
|
222
222
|
end
|
223
223
|
|
224
|
-
def
|
225
|
-
return @
|
224
|
+
def get_parameter(name)
|
225
|
+
return @_parameter_table[name.to_s]
|
226
226
|
end
|
227
227
|
|
228
228
|
def get_value(name)
|
229
229
|
name = name.to_s
|
230
|
-
return get_property(name) if has_property?(name) # allow overwrite
|
231
|
-
return
|
232
|
-
#if has_property?(name) ||
|
230
|
+
return get_property(name) if has_property?(name) # allow overwrite parameter by property
|
231
|
+
return get_parameter(name) if has_parameter?(name)
|
232
|
+
#if has_property?(name) || has_parameter?(name)
|
233
233
|
# return _get(name)
|
234
234
|
#end
|
235
|
-
msg = "
|
235
|
+
msg = "$(#{name}): no such property nor parameter."
|
236
236
|
#raise UndefinedPropertyError.new(msg, name)
|
237
237
|
raise RookError.new(msg)
|
238
238
|
end
|
239
239
|
|
240
|
-
def
|
240
|
+
def expand_value(value, filename=nil, linenum=nil)
|
241
241
|
case value
|
242
242
|
when String
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
243
|
+
begin
|
244
|
+
if value =~ /\A\$\(([a-zA-Z_]\w*)\)\z/
|
245
|
+
val = get_value($1)
|
246
|
+
else
|
247
|
+
val = value.gsub(/\$\(([a-zA-Z_]\w*)\)/) { get_value($1) }
|
248
|
+
end
|
249
|
+
rescue RookError => ex
|
250
|
+
#ex.filename = filename
|
251
|
+
#ex.linenum = linenum
|
252
|
+
raise ex
|
247
253
|
end
|
248
254
|
when Array
|
249
|
-
list = value.collect { |val|
|
255
|
+
list = value.collect { |val| expand_value(val) }
|
250
256
|
val = list
|
251
257
|
when Hash
|
252
258
|
hash = {}
|
253
|
-
value.each { |key, val| hash[key] =
|
259
|
+
value.each { |key, val| hash[key] = expand_value(val) }
|
254
260
|
val = hash
|
255
261
|
else
|
256
262
|
val = value
|
@@ -259,17 +265,17 @@ module Rook
|
|
259
265
|
end
|
260
266
|
|
261
267
|
def evaluate_expr(expr, filename='(expr)', linenum=1)
|
262
|
-
code = @
|
268
|
+
code = @_parameter_table.keys.collect { |name| "#{name}=@_parameter_table['#{name}'];" }
|
263
269
|
code << expr
|
264
|
-
return self.instance_eval(code.join, filename, linenum)
|
270
|
+
return self.instance_eval(code.join, filename.to_s, linenum)
|
265
271
|
end
|
266
272
|
|
267
273
|
def property_names
|
268
274
|
return @_property_table.keys
|
269
275
|
end
|
270
276
|
|
271
|
-
def
|
272
|
-
return @
|
277
|
+
def parameter_names
|
278
|
+
return @_parameter_table.keys
|
273
279
|
end
|
274
280
|
|
275
281
|
end
|
@@ -292,41 +298,70 @@ module Rook
|
|
292
298
|
|
293
299
|
|
294
300
|
def initialize(properties={}, options={})
|
295
|
-
@
|
301
|
+
@value_table = ValueTable.new
|
296
302
|
@properties = []
|
297
|
-
@
|
303
|
+
@parameters = []
|
298
304
|
properties.each do |name, value|
|
299
305
|
add_property({'name'=>name.to_s, 'value'=>value})
|
300
306
|
end
|
301
307
|
@recipes = []
|
302
308
|
@recipe_table = {}
|
303
309
|
@materials = []
|
304
|
-
@
|
310
|
+
@preparations = []
|
305
311
|
@forced = options[:forced]
|
306
312
|
#@verbose = options[:verbose]
|
307
|
-
|
313
|
+
@noexec = options[:noexec]
|
308
314
|
end
|
309
|
-
attr_reader :properties, :
|
310
|
-
attr_reader :materials, :
|
315
|
+
attr_reader :properties, :parameters
|
316
|
+
attr_reader :materials, :preparations, :recipes
|
311
317
|
#attr_reader :forced, :quiet, :noexec
|
312
318
|
|
313
319
|
|
314
320
|
def has_property?(name)
|
315
|
-
return @
|
321
|
+
return @value_table.has_property?(name)
|
316
322
|
end
|
317
323
|
|
318
|
-
def
|
319
|
-
return @
|
324
|
+
def has_parameter?(name)
|
325
|
+
return @value_table.has_parameter?(name)
|
320
326
|
end
|
321
327
|
|
322
328
|
def get_property(name)
|
323
|
-
return @
|
329
|
+
return @value_table.get_property(name)
|
330
|
+
end
|
331
|
+
|
332
|
+
def get_parameter(name)
|
333
|
+
return @value_table.get_parameter(name)
|
334
|
+
end
|
335
|
+
|
336
|
+
def set_property(name, value)
|
337
|
+
@value_table.set_property(name, value)
|
338
|
+
end
|
339
|
+
|
340
|
+
def set_parameter(name, value)
|
341
|
+
@value_table.set_parameter(name, value)
|
342
|
+
end
|
343
|
+
|
344
|
+
def get_value(name)
|
345
|
+
return @value_table.get_value(name)
|
324
346
|
end
|
325
347
|
|
326
|
-
def
|
327
|
-
return @
|
348
|
+
def property_names
|
349
|
+
return @value_table.property_names
|
350
|
+
end
|
351
|
+
|
352
|
+
def parameter_names
|
353
|
+
return @value_table.parameter_names
|
354
|
+
end
|
355
|
+
|
356
|
+
def _expand_value(value, linenum=nil)
|
357
|
+
return @value_table.expand_value(value, @filename, linenum)
|
358
|
+
end
|
359
|
+
|
360
|
+
def _evaluate_expr(expr, linenum=nil)
|
361
|
+
return @value_table.evaluate_expr(expr, @filename, linenum)
|
328
362
|
end
|
329
363
|
|
364
|
+
|
330
365
|
def load_books(cookbooks)
|
331
366
|
cookboos.each do |cookbook| load_book(cookbook) end
|
332
367
|
end
|
@@ -334,27 +369,27 @@ module Rook
|
|
334
369
|
|
335
370
|
def load_book(cookbook)
|
336
371
|
b = cookbook
|
337
|
-
#
|
338
|
-
b.
|
339
|
-
|
340
|
-
end if b.
|
372
|
+
# preparation
|
373
|
+
b.preparations.each do |hash|
|
374
|
+
add_preparation(hash['code'], b.bookname, hash['linenum'])
|
375
|
+
end if b.preparation
|
341
376
|
# properties
|
342
377
|
b.properties.each do |hash|
|
343
378
|
hash['bookname'] = b.bookname
|
344
379
|
add_property(hash, b.bookname)
|
345
380
|
end if b.properties
|
346
|
-
#
|
347
|
-
b.
|
381
|
+
# parameters
|
382
|
+
b.parameters.each do |hash|
|
348
383
|
hash['bookname'] = b.bookname
|
349
|
-
|
350
|
-
end if b.
|
384
|
+
add_parameter(hash, b.bookname)
|
385
|
+
end if b.parameters
|
351
386
|
# materials
|
352
387
|
b.materials.each do |nonprod|
|
353
|
-
|
388
|
+
add_material(nonprod)
|
354
389
|
end if b.materials
|
355
390
|
# recipes
|
356
391
|
b.recipes.each do |hash|
|
357
|
-
hash = @
|
392
|
+
hash = @value_table.expand_value(hash)
|
358
393
|
hash['bookname'] = b.bookname
|
359
394
|
recipe = Recipe.new(hash)
|
360
395
|
add_recipe(recipe)
|
@@ -371,8 +406,8 @@ module Rook
|
|
371
406
|
end
|
372
407
|
|
373
408
|
|
374
|
-
def
|
375
|
-
@
|
409
|
+
def add_preparation(code_str, bookname='', linenum=1)
|
410
|
+
@preparations << [code_str, bookname, linenum]
|
376
411
|
Util.evaluate(code_str, bookname, linenum) # or instance_eval?
|
377
412
|
end
|
378
413
|
|
@@ -380,69 +415,71 @@ module Rook
|
|
380
415
|
def add_property(hash, bookname='')
|
381
416
|
hash['access'] ||= 'public'
|
382
417
|
name = hash['name']
|
383
|
-
if
|
384
|
-
value =
|
418
|
+
if has_property?(name)
|
419
|
+
value = get_property(name)
|
385
420
|
else
|
386
421
|
if hash.key?('value')
|
387
|
-
value =
|
422
|
+
value = _expand_value(hash['value'])
|
388
423
|
elsif hash.key?('expr') || hash.key?('value*')
|
389
|
-
|
390
|
-
|
391
|
-
value =
|
424
|
+
code = hash.key?('expr') ? hash['expr'] : hash['value*']
|
425
|
+
code = _expand_value(code)
|
426
|
+
value = _evaluate_expr(code, hash['linenum'])
|
392
427
|
else
|
393
428
|
raise RookError.new("property '#{name}': no value.")
|
394
429
|
end
|
395
|
-
|
430
|
+
set_property(name, value)
|
396
431
|
hash['value'] = value
|
397
432
|
@properties << hash
|
398
433
|
end
|
399
434
|
#eval "$#{name} = value"
|
435
|
+
instance_variable_set("@#{name}", value)
|
400
436
|
end
|
401
437
|
|
402
438
|
|
403
|
-
def
|
439
|
+
def add_parameter(hash, bookname='')
|
404
440
|
name = hash['name']
|
405
|
-
if
|
406
|
-
@
|
441
|
+
if has_parameter?(name)
|
442
|
+
@parameters.delete_if { |h| h['name'] == name }
|
407
443
|
end
|
408
444
|
if hash.key?('value')
|
409
|
-
value =
|
410
|
-
elsif hash.key?('
|
411
|
-
|
412
|
-
linenum = hash['linenum']
|
413
|
-
|
414
|
-
value =
|
445
|
+
value = _expand_value(hash['value'])
|
446
|
+
elsif hash.key?('value*')
|
447
|
+
code = hash['value*']
|
448
|
+
linenum = hash['linenum']
|
449
|
+
code = _expand_value(code)
|
450
|
+
value = _evaluate_expr(code, linenum)
|
415
451
|
else
|
416
|
-
raise RookError.new("
|
452
|
+
raise RookError.new("parameter '#{name}': no value.")
|
417
453
|
end
|
418
|
-
|
454
|
+
set_parameter(name, value)
|
419
455
|
hash['value'] = value
|
420
|
-
@
|
456
|
+
@parameters << hash
|
421
457
|
end
|
422
458
|
|
423
459
|
|
424
460
|
def add_material(material_str)
|
425
|
-
mat_str =
|
461
|
+
mat_str = _expand_value(material_str)
|
426
462
|
@materials << mat_str
|
427
463
|
end
|
428
464
|
|
429
465
|
|
430
|
-
def add_recipe_hash(hash)
|
431
|
-
%w[ingreds byprods coprods
|
432
|
-
if hash.key?("#{key}*")
|
433
|
-
val = hash.delete("#{key}*")
|
434
|
-
assert val.is_a?(String), "val.class=#{val.class}"
|
435
|
-
val =
|
436
|
-
val = [ val ] unless val.is_a?(Array)
|
437
|
-
hash[key] = val
|
438
|
-
elsif hash.key?(key)
|
439
|
-
val =
|
440
|
-
hash[key] = val
|
441
|
-
end
|
442
|
-
end
|
443
|
-
r = Recipe.new(hash['product'])
|
444
|
-
add_recipe(r)
|
445
|
-
end
|
466
|
+
# def add_recipe_hash(hash)
|
467
|
+
# %w[ingreds byprods coprods toppings].each do |key|
|
468
|
+
# if hash.key?("#{key}*")
|
469
|
+
# val = hash.delete("#{key}*")
|
470
|
+
# assert val.is_a?(String), "val.class=#{val.class}"
|
471
|
+
# val = _evaluate_expr(val)
|
472
|
+
# val = [ val ] unless val.is_a?(Array)
|
473
|
+
# hash[key] = val
|
474
|
+
# elsif hash.key?(key)
|
475
|
+
# val = _evaluate_expr(val)
|
476
|
+
# hash[key] = val
|
477
|
+
# end
|
478
|
+
# end
|
479
|
+
# r = Recipe.new(hash['product'])
|
480
|
+
# add_recipe(r)
|
481
|
+
# end
|
482
|
+
|
446
483
|
|
447
484
|
def add_recipe(recipe)
|
448
485
|
@recipes.delete_if { |r| r.product == recipe.product } if @recipe_table[recipe.product]
|
@@ -515,7 +552,7 @@ module Rook
|
|
515
552
|
|
516
553
|
## ingredients
|
517
554
|
ingreds = recipe.ingreds ? recipe.ingreds.dup : []
|
518
|
-
ingreds.concat(recipe.
|
555
|
+
ingreds.concat(recipe.toppings.find_all { |f| test(?e, f) }) if recipe.toppings
|
519
556
|
# ingreds.each do |ingred|
|
520
557
|
# flag = cook(ingred, cooking, level+1, recipe.verbose?, recipe.fingerprint)
|
521
558
|
# flag_exec = true if flag
|
@@ -545,7 +582,7 @@ module Rook
|
|
545
582
|
|
546
583
|
## invoke ingredients' recipe
|
547
584
|
#ingreds = recipe.ingreds ? recipe.ingreds.dup : []
|
548
|
-
#ingreds.concat(recipe.
|
585
|
+
#ingreds.concat(recipe.toppings.find_all { |f| test(?e, f) }) if recipe.toppings
|
549
586
|
ingreds.each do |ingred|
|
550
587
|
flag = cook(ingred, cooking, level+1, recipe.verbose?, recipe.fingerprint)
|
551
588
|
flag_exec = true if flag
|
@@ -564,7 +601,8 @@ module Rook
|
|
564
601
|
end
|
565
602
|
report(product, level, recipe.verbose?)
|
566
603
|
begin
|
567
|
-
recipe.invoke(@
|
604
|
+
#recipe.invoke(@value_table)
|
605
|
+
recipe.invoke(self)
|
568
606
|
rescue => ex
|
569
607
|
prods = [ recipe.product ]
|
570
608
|
prods += recipe.coprods if recipe.coprods
|
@@ -578,7 +616,7 @@ module Rook
|
|
578
616
|
end
|
579
617
|
|
580
618
|
## validate whether product is generated
|
581
|
-
unless recipe.symbolic? || test(?e, product)
|
619
|
+
unless recipe.symbolic? || @noexec || test(?e, product)
|
582
620
|
raise RookError.new("product '#{Util.to_str(product)}': not generated")
|
583
621
|
end
|
584
622
|
|