Module: BBMB::Util::TargetDir

Defined in:
lib/bbmb/util/target_dir.rb

Class Method Summary collapse

Class Method Details

.send_order(order) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bbmb/util/target_dir.rb', line 12

def TargetDir.send_order(order)
  content = order.to_target_format
  basename = BBMB.config.tmpfile_basename
  SBSM.info("TargetDir.send_order #{order.order_id} basename #{basename} -> #{BBMB.config.order_destinations}")
  BBMB.config.order_destinations.each { |destination|
    uri = URI.parse(File.join(destination, order.filename))
    case uri.scheme
    when "ftp"
      Tempfile.open(basename) { |tmp|
        tmp.puts(content)
        tmp.flush
        Net::FTP.open(uri.host, uri.user, uri.password) { |ftp|
          ftp.put(tmp.path, uri.path)
        }
      }
    else
      path = File.expand_path(uri.path, BBMB.config.bbmb_dir)
      File.open(path, 'w') { |fh|
        fh.puts content
      }
    end
  }
end