Class: Hadupils::Extensions::HiveRC::Dynamic

Inherits:
Object
  • Object
show all
Includes:
HiveOpt
Defined in:
lib/hadupils/extensions.rb

Overview

Manages dynamic hive initialization files, assembling a temporary file and understanding how to write assets/lines into the initialization file for use with hive’s -i option.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HiveOpt

#hive_opts

Constructor Details

#initializeDynamic

Sets up a wrapped file, using the class’ file_handler,



188
189
190
# File 'lib/hadupils/extensions.rb', line 188

def initialize
  @file = self.class.file_handler.new('hadupils-hiverc')
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



173
174
175
# File 'lib/hadupils/extensions.rb', line 173

def file
  @file
end

Class Method Details

.file_handlerObject

The class to use for creating the files; defaults to ::Tempfile



183
184
185
# File 'lib/hadupils/extensions.rb', line 183

def self.file_handler
  @file_handler || ::Tempfile
end

.file_handler=(handler) ⇒ Object

This will allow us to change what handles the dynamic files.



178
179
180
# File 'lib/hadupils/extensions.rb', line 178

def self.file_handler=(handler)
  @file_handler = handler
end

Instance Method Details

#closeObject



196
197
198
# File 'lib/hadupils/extensions.rb', line 196

def close
  @file.close
end

#pathObject



192
193
194
# File 'lib/hadupils/extensions.rb', line 192

def path
  ::File.expand_path @file.path
end

#write(items) ⇒ Object

Writes the items to the file, using #hiverc_command on each item that responds to it (Hadupils::Assets::* instances) and #to_s on the rest. Separates lines by newline, and provides a trailing newline. However, the items are responsible for ensuring the proper terminating semicolon. The writes are flushed to the underlying file immediately afterward.



205
206
207
208
209
210
211
212
213
214
215
# File 'lib/hadupils/extensions.rb', line 205

def write(items)
  lines = items.collect do |item|
    if item.respond_to? :hiverc_command
      item.hiverc_command
    else
      item.to_s
    end
  end
  @file.write(lines.join("\n") + "\n")
  @file.flush
end