Class: Meathook::Command
- Inherits:
-
Object
- Object
- Meathook::Command
- Defined in:
- lib/meathook/command.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#halt ⇒ Object
Returns the value of attribute halt.
-
#hookname ⇒ Object
Returns the value of attribute hookname.
-
#match ⇒ Object
Returns the value of attribute match.
-
#message ⇒ Object
Returns the value of attribute message.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(n, hn, opts) ⇒ Command
constructor
A new instance of Command.
Constructor Details
#initialize(n, hn, opts) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/meathook/command.rb', line 7 def initialize(n, hn, opts) self.name = n self.hookname = hn self.command = opts.fetch('command') self.condition = opts.fetch('condition') self.halt = opts['halt'] || false self. = opts["message"] self.match = false end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/meathook/command.rb', line 4 def command @command end |
#condition ⇒ Object
Returns the value of attribute condition.
4 5 6 |
# File 'lib/meathook/command.rb', line 4 def condition @condition end |
#halt ⇒ Object
Returns the value of attribute halt.
4 5 6 |
# File 'lib/meathook/command.rb', line 4 def halt @halt end |
#hookname ⇒ Object
Returns the value of attribute hookname.
3 4 5 |
# File 'lib/meathook/command.rb', line 3 def hookname @hookname end |
#match ⇒ Object
Returns the value of attribute match.
5 6 7 |
# File 'lib/meathook/command.rb', line 5 def match @match end |
#message ⇒ Object
Returns the value of attribute message.
4 5 6 |
# File 'lib/meathook/command.rb', line 4 def @message end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/meathook/command.rb', line 3 def name @name end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/meathook/command.rb', line 19 def execute output = `#{command}` exit_code = ($?) case condition when "empty" then self.match = (output =~ /\S/ ? false : true) when "nonempty" then self.match = (output =~ /\S/ ? true : false) when "failed" then self.match = (exit_code != 0) when "successful" then self.match = (exit_code == 0) else raise("The condition '#{condition}' was not recognized") end if self.match if self. and self. =~ /\S/ warn "" warn "============================================================" warn " Git Hook '#{hookname}' :: '#{name}' triggered" warn "" warn " #{}" warn "" end if self.halt exit(1) else exit(0) end end end |