class Ronin::Gen::FileGenerator
A {Generator} class for creating files.
Attributes
path[RW]
The file to generate
Public Class Methods
new(path=nil,options={},&block)
click to toggle source
Initializes the file generator.
@param [String] path
The path to the file to be generated.
@param [Hash{Symbol => Object}] options
Additional options for the generator.
@yield [generator]
The given block will be passed the newly created generator.
@yieldparam [FileGenerator]
The newly created generator.
@api semipublic
@since 1.2.0
Calls superclass method
# File lib/ronin/gen/file_generator.rb, line 51 def initialize(path=nil,options={},&block) @path = path super(options,&block) end
Protected Class Methods
file_extension(ext=nil)
click to toggle source
The file extension to append to all paths.
@param [String] ext
The new file extension to use.
@return [String, nil]
The file extension.
@since 1.0.0
@api semipublic
# File lib/ronin/gen/file_generator.rb, line 103 def self.file_extension(ext=nil) if ext @file_extension = ext.to_s else @file_extension ||= if superclass < FileGenerator superclass.file_extension end end end
Public Instance Methods
generate!()
click to toggle source
Sets up the generator and calls {#generate}.
@raise [RuntimeError]
{#path} was not set.
@since 1.2.0
@api public
Calls superclass method
# File lib/ronin/gen/file_generator.rb, line 67 def generate! unless @path raise("#{self.class}#path was not set") end super end
setup()
click to toggle source
Sets up the File generator.
@since 1.1.0
@api semipublic
# File lib/ronin/gen/file_generator.rb, line 82 def setup if (self.class.file_extension && File.extname(@path).empty?) @path += ".#{self.class.file_extension}" end end