Method: Rook::Cookbook#validate_rubycode

Defined in:
lib/rook/cookbook.rb

#validate_rubycodeObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/rook/cookbook.rb', line 197

def validate_rubycode
  lines = []
  @preparations.each do |hash|
    _add_code(lines, hash, 'code')
  end if @preparations
  @properties.each do |hash|
    _add_code(lines, hash, 'value*') if hash.key?('value*')
  end if @properties
  @parameters.each do |hash|
    _add_code(lines, hash, 'value*') if hash.key?('value*')
  end if @parameters
  @recipes.each do |hash|
    _add_code(lines, hash, 'method*') if hash.key?('method*')
    hash['params'].each do |h|
      name = h['name']
      _add_code(lines, h, 'value') if name[-1] == ?*
    end if hash.key?('params')
  end if @recipes
  #
  lines.shift      # ignore first item
  code = ''
  lines.each do |line|
    code << (line || "") << "\n"
  end
  tmpfilename = "#{@bookname}."   # or user tmpfile library
  begin
    File.open(tmpfilename, 'w') { |f| f.write(code) }
    #case RUBY_PLATFORM
    #when /linux/, /bsd/, /darwin/, /cygwin/
      out = `ruby -wc #{tmpfilename} 2>&1`
      puts out.gsub(/^#{tmpfilename}/, bookname)
    #else
    #  system "ruby -wc #{tmpfilename}"
    #end
  ensure
    File.unlink(tmpfilename) if test(?f, tmpfilename)
  end

end