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



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

def self.hadoop_home
  ENV['HADOOP_HOME']
end

.hadoop_jarsObject



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

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

.setupObject



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

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

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



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

def self.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