Module: BlackStack::Deployer::MatchModule

Included in:
Match
Defined in:
lib/blackstack-deployer.rb

Overview

define attributes and methods of a command’s match

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matchObject

Returns the value of attribute match.



447
448
449
# File 'lib/blackstack-deployer.rb', line 447

def match
  @match
end

Class Method Details

.descriptor_errors(m) ⇒ Object



449
450
451
452
453
454
455
# File 'lib/blackstack-deployer.rb', line 449

def self.descriptor_errors(m)
  errors = []
  # validate the match is a regular expresion
  errors << "The match is not a regex" unless m.is_a?(Regexp)
  # 
  errors.uniq
end

Instance Method Details

#initialize(h) ⇒ Object

def self.descriptor_error(h)



457
458
459
460
461
# File 'lib/blackstack-deployer.rb', line 457

def initialize(h)
  errors = BlackStack::Deployer::MatchModule.descriptor_errors(h)
  raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0
  self.match = h
end

#to_hashObject



463
464
465
466
467
# File 'lib/blackstack-deployer.rb', line 463

def to_hash
  h = {}
  h[:match] = self.match
  h
end

#validate(output) ⇒ Object



469
470
471
472
473
# File 'lib/blackstack-deployer.rb', line 469

def validate(output)
  errors = []
  errors << "The output of the command does not match the regular expression #{self.match.inspect}" unless output.match(self.match)
  errors
end