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.



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

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

Instance Method Details

#notunperform(dir) ⇒ Object



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

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



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

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



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

def unperform(dir)
  # nothing
end