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.



102
103
104
# File 'lib/awestruct/cli/manifest.rb', line 102

def initialize(path)
  @path = path
end

Instance Method Details

#perform(dir) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/awestruct/cli/manifest.rb', line 106

def perform(dir)
  p = File.join( dir, @path ) 
  if ( File.exist?( p ) )
    $LOG.error "Exists: #{p}" if $LOG.error?
    return
  end
  if ( ! 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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/awestruct/cli/manifest.rb', line 120

def unperform(dir)
  p = File.join( dir, @path ) 
  if ( ! File.exist?( p ) )
    $LOG.error "Does not exist: #{p}" if $LOG.error?
    return
  end
  if ( ! 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