Class: Pups::FileCommand

Inherits:
Command show all
Defined in:
lib/pups/file_command.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#interpolate_params, interpolate_params, run

Constructor Details

#initializeFileCommand

Returns a new instance of FileCommand.



14
15
16
17
# File 'lib/pups/file_command.rb', line 14

def initialize
  @params = {}
  @type = :bash
end

Instance Attribute Details

#chmodObject

Returns the value of attribute chmod.



2
3
4
# File 'lib/pups/file_command.rb', line 2

def chmod
  @chmod
end

#contentsObject

Returns the value of attribute contents.



2
3
4
# File 'lib/pups/file_command.rb', line 2

def contents
  @contents
end

#paramsObject

Returns the value of attribute params.



2
3
4
# File 'lib/pups/file_command.rb', line 2

def params
  @params
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'lib/pups/file_command.rb', line 2

def path
  @path
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/pups/file_command.rb', line 2

def type
  @type
end

Class Method Details

.from_hash(hash, params) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/pups/file_command.rb', line 4

def self.from_hash(hash, params)
  command = new
  command.path = hash["path"]
  command.contents = hash["contents"]
  command.chmod = hash["chmod"]
  command.params = params

  command
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pups/file_command.rb', line 23

def run
  path = interpolate_params(@path)

  `mkdir -p #{File.dirname(path)}`
  File.open(path, "w") do |f|
    f.write(interpolate_params(contents))
  end
  if @chmod
    `chmod #{@chmod} #{path}`
  end
  Pups.log.info("File > #{path}  chmod: #{@chmod}")
end