Class: Patcmd::Task
- Inherits:
-
Object
- Object
- Patcmd::Task
- Defined in:
- lib/patcmd/task.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#command ⇒ Object
Returns the value of attribute command.
-
#description ⇒ Object
Returns the value of attribute description.
-
#env ⇒ Object
Returns the value of attribute env.
-
#group ⇒ Object
Returns the value of attribute group.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(name, attributes = {}) ⇒ Task
constructor
A new instance of Task.
Constructor Details
#initialize(name, attributes = {}) ⇒ Task
Returns a new instance of Task.
7 8 9 10 11 12 13 14 |
# File 'lib/patcmd/task.rb', line 7 def initialize(name, attributes = {}) @name = name @description = attributes["description"] || "" @group = attributes["group"] || "default" @command = attributes["command"] @args = attributes["args"] || [] @env = attributes["env"] || {} end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def args @args end |
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def command @command end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def description @description end |
#env ⇒ Object
Returns the value of attribute env.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def env @env end |
#group ⇒ Object
Returns the value of attribute group.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def group @group end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/patcmd/task.rb', line 5 def name @name end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/patcmd/task.rb', line 16 def execute # Save original environment variables original_env = ENV.to_hash # Set the specified environment variables @env.each { |key, value| ENV[key] = value } # Build and run the command string full_command = [@command, *@args].join(" ") system(full_command) # Restore original environment. ENV.replace(original_env) end |