Class: Awestruct::CLI::Manifest::MkDir

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/manifest.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MkDir

Returns a new instance of MkDir.



97
98
99
# File 'lib/awestruct/cli/manifest.rb', line 97

def initialize(path)
  @path = path
end

Instance Method Details

#perform(dir) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/awestruct/cli/manifest.rb', line 101

def perform(dir)
  p = File.join(dir, @path)
  if File.exist?(p)
    $LOG.error "Exists: #{p}" if $LOG.error?
    return
  end
  unless File.directory?(File.dirname(p))
    $LOG.error "Does not exist: #{File.dirname(p)}" if $LOG.error?
    return
  end
  $LOG.info "Create directory: #{p}" if $LOG.info?
  FileUtils.mkdir(p)
end

#unperform(dir) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/awestruct/cli/manifest.rb', line 115

def unperform(dir)
  p = File.join(dir, @path)
  unless File.exist?(p)
    $LOG.error "Does not exist: #{p}" if $LOG.error?
    return
  end
  unless File.directory?(p)
    $LOG.error "Not a directory: #{p}" if $LOG.error?
    return
  end
  if Dir.entries(p) != 2
    $LOG.error "Not empty: #{p}" if $LOG.error?
    return
  end
  $LOG.info "Remove: #{p}" if $LOG.info?
  FileUtils.rmdir(p)
end