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,
188 189 190 |
# File 'lib/hadupils/extensions.rb', line 188 def initialize @file = self.class.file_handler.new('hadupils-hiverc') end |
Instance Attribute Details
#file ⇒ Object (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_handler ⇒ Object
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
#close ⇒ Object
196 197 198 |
# File 'lib/hadupils/extensions.rb', line 196 def close @file.close end |
#path ⇒ Object
192 193 194 |
# File 'lib/hadupils/extensions.rb', line 192 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.
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 |