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.



18
19
20
21
# File 'lib/pups/file_command.rb', line 18

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

Instance Attribute Details

#chmodObject

Returns the value of attribute chmod.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def chmod
  @chmod
end

#chownObject

Returns the value of attribute chown.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def chown
  @chown
end

#contentsObject

Returns the value of attribute contents.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def contents
  @contents
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def params
  @params
end

#pathObject

Returns the value of attribute path.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def path
  @path
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/pups/file_command.rb', line 5

def type
  @type
end

Class Method Details

.from_hash(hash, params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/pups/file_command.rb', line 7

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

  command
end

Instance Method Details

#runObject



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

def run
  path = interpolate_params(@path)

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