Class: Hjc::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/hjc/util.rb

Constant Summary collapse

TMP_DIR =
'tmp'

Class Method Summary collapse

Class Method Details

.hadoop_homeObject



24
25
26
# File 'lib/hjc/util.rb', line 24

def hadoop_home
  ENV['HADOOP_HOME']
end

.hadoop_jarsObject



16
17
18
19
20
21
22
# File 'lib/hjc/util.rb', line 16

def hadoop_jars
  jars = []
  ['', 'lib', 'contrib/streaming'].each do |path|
    jars.concat Dir.glob(File.join(hadoop_home, path, "*.jar"))
  end
  jars
end

.rel_path(file) ⇒ Object



42
43
44
# File 'lib/hjc/util.rb', line 42

def rel_path(file)
  File.join(TMP_DIR, File.basename(file.path))
end

.setupObject



8
9
10
11
12
13
14
# File 'lib/hjc/util.rb', line 8

def setup
  hadoop_jars.each do |jar|
    require jar # fro JRuby
  end
  
  $CLASSPATH << "#{hadoop_home}/conf"
end

.to_temp_file(filename, body, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hjc/util.rb', line 28

def to_temp_file(filename, body, options={})
  file = Tempfile.new(filename, TMP_DIR)
  file.print body
  file.close

  unless options.empty?
    if options.keys.include? :mod
      File.chmod(options[:mod], file.path)
    end
  end

  file
end