Class: Freyia::Automations::EmptyDirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/freyia/automations/empty_directory.rb

Overview

Class which holds create directory logic. This is the base class for other automations like create_file and directory.

This implementation is based in Templater automations, created by Jonas Nicklas and Michael S. Klishin under MIT LICENSE.

Direct Known Subclasses

CreateFile, Directory, InjectIntoFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, destination, **config) ⇒ EmptyDirectory

Initializes given the source and destination.

Parameters

Parameters:

  • base (Object<Freyia::Setup>)

    A Base instance (or any object with the Setup mixin)

  • source (String)

    Relative path to the source of this file

  • destination (String)

    Relative path to the destination of this file

  • config (Hash)

    give verbose: false to not log the status.



32
33
34
35
36
# File 'lib/freyia/automations/empty_directory.rb', line 32

def initialize(base, destination, **config)
  @base = base
  @config = { verbose: true }.merge(config)
  self.destination = destination
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



22
23
24
# File 'lib/freyia/automations/empty_directory.rb', line 22

def base
  @base
end

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/freyia/automations/empty_directory.rb', line 22

def config
  @config
end

#destinationObject

Returns the value of attribute destination.



22
23
24
# File 'lib/freyia/automations/empty_directory.rb', line 22

def destination
  @destination
end

#given_destinationObject (readonly)

Returns the value of attribute given_destination.



22
23
24
# File 'lib/freyia/automations/empty_directory.rb', line 22

def given_destination
  @given_destination
end

#relative_destinationObject (readonly)

Returns the value of attribute relative_destination.



22
23
24
# File 'lib/freyia/automations/empty_directory.rb', line 22

def relative_destination
  @relative_destination
end

Instance Method Details

#callObject



45
46
47
48
49
50
# File 'lib/freyia/automations/empty_directory.rb', line 45

def call
  invoke_with_conflict_check do
    require "fileutils"
    ::FileUtils.mkdir_p(destination)
  end
end

#exists?Boolean

Checks if the destination file already exists.

Returns:

  • (Boolean)

    true if the file exists, false otherwise.



41
42
43
# File 'lib/freyia/automations/empty_directory.rb', line 41

def exists?
  ::File.exist?(destination)
end