Class: Pups::FileCommand
Instance Attribute Summary collapse
-
#chmod ⇒ Object
Returns the value of attribute chmod.
-
#chown ⇒ Object
Returns the value of attribute chown.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#params ⇒ Object
Returns the value of attribute params.
-
#path ⇒ Object
Returns the value of attribute path.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ FileCommand
constructor
A new instance of FileCommand.
- #run ⇒ Object
Methods inherited from Command
#interpolate_params, interpolate_params, run
Constructor Details
#initialize ⇒ FileCommand
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
#chmod ⇒ Object
Returns the value of attribute chmod.
5 6 7 |
# File 'lib/pups/file_command.rb', line 5 def chmod @chmod end |
#chown ⇒ Object
Returns the value of attribute chown.
5 6 7 |
# File 'lib/pups/file_command.rb', line 5 def chown @chown end |
#contents ⇒ Object
Returns the value of attribute contents.
5 6 7 |
# File 'lib/pups/file_command.rb', line 5 def contents @contents end |
#params ⇒ Object
Returns the value of attribute params.
5 6 7 |
# File 'lib/pups/file_command.rb', line 5 def params @params end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/pups/file_command.rb', line 5 def path @path end |
#type ⇒ Object
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
#run ⇒ Object
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 |