Class: Hadupils::Extensions::HiveRC::Dynamic
- Inherits:
-
Object
- Object
- Hadupils::Extensions::HiveRC::Dynamic
- 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
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
-
.file_handler ⇒ Object
The class to use for creating the files; defaults to ::Tempfile.
-
.file_handler=(handler) ⇒ Object
This will allow us to change what handles the dynamic files.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ Dynamic
constructor
Sets up a wrapped file, using the class’ file_handler,.
- #path ⇒ Object
-
#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.
Methods included from HiveOpt
Constructor Details
#initialize ⇒ Dynamic
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
#file ⇒ Object (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_handler ⇒ Object
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
#close ⇒ Object
186 187 188 |
# File 'lib/hadupils/extensions.rb', line 186 def close @file.close end |
#path ⇒ Object
182 183 184 |
# File 'lib/hadupils/extensions.rb', line 182 def path ::File. @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 |