Class: Pineapples::Actions::CopyFile

Inherits:
CreateFile show all
Defined in:
lib/pineapples/actions/copy_file.rb

Direct Known Subclasses

Rails::CopyMigration

Constant Summary

Constants inherited from Action

Action::STATUS_COLORS

Instance Attribute Summary collapse

Attributes inherited from CreateFile

#content

Attributes inherited from EmptyDirectory

#skip, #target

Attributes inherited from Action

#colors, #generator, #options

Instance Method Summary collapse

Methods inherited from CreateFile

#identical?, #render

Methods inherited from EmptyDirectory

#exists?, #revoke!

Methods inherited from Action

colors, inherited, #skip?, status_color

Constructor Details

#initialize(generator, source, target, options, &block) ⇒ CopyFile

Returns a new instance of CopyFile.



31
32
33
34
35
36
# File 'lib/pineapples/actions/copy_file.rb', line 31

def initialize(generator, source, target, options, &block)
  @source  = File.expand_path(generator.find_in_source_paths(source.to_s))
  @content = File.binread(@source)
  @content = block.call(@content) if block
  super(generator, target, @content, options)
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



29
30
31
# File 'lib/pineapples/actions/copy_file.rb', line 29

def source
  @source
end

Instance Method Details

#invoke!Object



38
39
40
41
42
43
44
# File 'lib/pineapples/actions/copy_file.rb', line 38

def invoke!
  super
  if options[:mode] == :preserve
    mode = File.stat(source).mode
    generator.chmod(target.fullpath, mode, options)
  end
end