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,



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

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



163
164
165
# File 'lib/hadupils/extensions.rb', line 163

def file
  @file
end

Class Method Details

.file_handlerObject

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



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

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

.file_handler=(handler) ⇒ Object

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



168
169
170
# File 'lib/hadupils/extensions.rb', line 168

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

Instance Method Details

#closeObject



186
187
188
# File 'lib/hadupils/extensions.rb', line 186

def close
  @file.close
end

#pathObject



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

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.



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/hadupils/extensions.rb', line 195

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