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.



95
96
97
# File 'lib/awestruct/cli/manifest.rb', line 95

def initialize(path)
  @path = path
end

Instance Method Details

#perform(dir) ⇒ Object



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

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



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

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