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.



342
343
344
# File 'lib/blackstack-deployer.rb', line 342

def match
  @match
end

Class Method Details

.descriptor_errors(m) ⇒ Object



344
345
346
347
348
349
350
# File 'lib/blackstack-deployer.rb', line 344

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)



352
353
354
355
356
# File 'lib/blackstack-deployer.rb', line 352

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



358
359
360
361
362
# File 'lib/blackstack-deployer.rb', line 358

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

#validate(output) ⇒ Object



364
365
366
367
368
# File 'lib/blackstack-deployer.rb', line 364

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