class Ronin::Gen::DirGenerator

A {Generator} class for creating directories.

Attributes

path[RW]

The directory to generate

Public Class Methods

new(path=nil,options={},&block) click to toggle source

Initializes the directory generator.

@param [String] path

The path to the directory 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 [DirGenerator]

The newly created generator.

@api semipublic

@since 1.2.0

Calls superclass method
# File lib/ronin/gen/dir_generator.rb, line 53
def initialize(path=nil,options={},&block)
  @path = path

  super(options,&block)
end

Public Instance Methods

generate!() click to toggle source

Creates the directory and invokes the generator.

@raise [RuntimeError]

{#path} was not set.

@api public

@since 1.1.0

Calls superclass method
# File lib/ronin/gen/dir_generator.rb, line 69
def generate!
  unless @path
    raise("#{self.class}#path was not set")
  end

  FileUtils.mkdir_p(@path)
  FileUtils.chdir(@path) { super }
end

Protected Instance Methods

chdir(path='.') click to toggle source

Changes current working directory, relative to the generated directory.

@param [String] path

The path within the generated directory to switch to.

@yield []

The given block will be ran after the current working directory
has been changed. After the block has returned, the current working
directory will be changed back.

@since 1.1.0

@see rubydoc.info/stdlib/core/Dir#chdir-class_method

Calls superclass method
# File lib/ronin/gen/dir_generator.rb, line 95
def chdir(path='.')
  super(File.join(@path,path),&block)
end