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



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

def initialize(path)
  @path = path
end

Instance Method Details

#perform(dir) ⇒ Object



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

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



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

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