Class: Hjc::Util
- Inherits:
-
Object
- Object
- Hjc::Util
- Defined in:
- lib/hjc/util.rb
Constant Summary collapse
- TMP_DIR =
'tmp'
Class Method Summary collapse
- .hadoop_home ⇒ Object
- .hadoop_jars ⇒ Object
- .rel_path(file) ⇒ Object
- .setup ⇒ Object
- .to_temp_file(filename, body, options = {}) ⇒ Object
Class Method Details
.hadoop_home ⇒ Object
24 25 26 |
# File 'lib/hjc/util.rb', line 24 def hadoop_home ENV['HADOOP_HOME'] end |
.hadoop_jars ⇒ Object
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 |
.setup ⇒ Object
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, ={}) file = Tempfile.new(filename, TMP_DIR) file.print body file.close unless .empty? if .keys.include? :mod File.chmod([:mod], file.path) end end file end |