Method: Roma::Mkconfig#save_data

Defined in:
lib/roma/tools/mkconfig.rb

#save_data(res) ⇒ Object

make config.rb based on input data



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/roma/tools/mkconfig.rb', line 511

def save_data(res)
  if res.key?("storage")
    case res["storage"].value
    when "Ruby Hash"
      req = "rh_storage"
      storage = "RubyHashStorage"
    when "Tokyo Cabinet"
      req = "tc_storage"
      storage = "TCStorage"
      bnum = Calculate.get_bnum(res)
      bnum = 5000000 if bnum < 5000000
      xmsiz = Calculate.get_xmsize_max(res)
    when "Groonga"
      req = "groonga_storage"
      storage = "GroongaStorage"
      bnum = Calculate.get_bnum(res)
      bnum = 5000000 if bnum < 5000000
      xmsiz = Calculate.get_xmsize_max(res)
    end
  end

  if res.key?("language")
    fd = Calculate.get_fd(res)
    print "\r\nPlease set FileDescriptor bigger than #{fd}.\r\n\r\n" 
  end

  body = ""
  open(CONFIG_TEMPLATE_PATH, "r") do |f|
    body = f.read
  end

  if req
    body = ch_assign(body, "require", " ", "roma\/storage\/#{req}")
    body = ch_assign(body, "STORAGE_CLASS", "Roma::Storage::#{storage}")

    case req
    when "rh_storage"
      body = ch_assign(body, "STORAGE_OPTION","")
    when /^(tc_storage|groonga_storage)$/
      body = ch_assign(body, "STORAGE_OPTION", "bnum=#{bnum}\#xmsiz=#{xmsiz}\#opts=d#dfunit=10")
    end
  end

  if res.key?("plugin")
    body = ch_assign(body, "PLUGIN_FILES", res["plugin"].value)
  end

  open(CONFIG_OUT_PATH, "w") do |f|
    f.flock(File::LOCK_EX)
    f.puts body
    f.truncate(f.tell)
    f.flock(File::LOCK_UN)
  end

  puts "Before"
  Box.print_with_box(@defaults)

  re_require(CONFIG_OUT_PATH, Config)
  results = load_config([:STORAGE_CLASS, :STORAGE_OPTION, :PLUGIN_FILES])
  print "\r\nAfter\r\n"
  Box.print_with_box(results)
  print "\r\nMkconfig is finish.\r\n"
  print "\r\nIf you need, change directory path about LOG, RTTABLE, STORAGE, WB and other setting.\r\n\r\n"
end