Class: Awestruct::CLI::Manifest::CopyFile

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

Instance Method Summary collapse

Constructor Details

#initialize(path, input_path, opts = {}) ⇒ CopyFile

Returns a new instance of CopyFile



190
191
192
193
194
# File 'lib/awestruct/cli/manifest.rb', line 190

def initialize(path, input_path, opts = {})
  @path = path
  @input_path = input_path
  @overwrite = opts[:overwrite]
end

Instance Method Details

#notunperform(dir) ⇒ Object



214
215
216
217
218
219
220
221
222
# File 'lib/awestruct/cli/manifest.rb', line 214

def notunperform(dir)
  p = File.join(@dir, p)
  unless File.exist?(p)
    $LOG.error "Does not exist: #{p}" if $LOG.error?
    return
  end
  $LOG.info "Remove: #{p}" if $LOG.info?
  FileUtils.rm(p)
end

#perform(dir) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/awestruct/cli/manifest.rb', line 196

def perform(dir)
  p = File.join(dir, @path)
  if !@overwrite && File.exist?(p)
    $LOG.error "Exists: #{p}" if $LOG.error?
    return
  end
  unless File.directory?(File.dirname(p))
    $LOG.error "No directory: #{File.dirname(p)}" if $LOG.error?
    return
  end
  $LOG.info "Create file: #{p}" if $LOG.info?
  File.open(p, 'w') { |f| f.write(File.read(@input_path)) }
end

#unperform(dir) ⇒ Object



210
211
212
# File 'lib/awestruct/cli/manifest.rb', line 210

def unperform(dir)
  # nothing
end