Module: BlackStack::Deployer::NoMatchModule

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

Overview

define attributes and methods of a command’s nomatch

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_descriptionObject

Returns the value of attribute error_description.



436
437
438
# File 'lib/blackstack-deployer.rb', line 436

def error_description
  @error_description
end

#nomatchObject

Returns the value of attribute nomatch.



436
437
438
# File 'lib/blackstack-deployer.rb', line 436

def nomatch
  @nomatch
end

Class Method Details

.descriptor_errors(m) ⇒ Object



438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/blackstack-deployer.rb', line 438

def self.descriptor_errors(m)
  errors = []
  # validate the nomatch is a regular expresion
  errors << "Each nomatch is not a regex nor a hash" unless m.is_a?(Hash) || m.is_a?(Regexp)
  # if m is a hash
  if m.is_a?(Hash)
    # validate: the hash m has a key :nomatch
    errors << "The hash descriptor of the nomatch does not have a key :nomatch" unless m.has_key?(:nomatch)
    # validate: the value of m[:nomatch] is a string
    errors << "The value of the key :nomatch is not a regex" unless m[:nomatch].is_a?(Regexp)
    # validate: the hash m has a key :error_description
    errors << "The hash descriptor of the nomatch does not have a key :error_description" unless m.has_key?(:error_description)
    # validate: the value of m[:error_description] is a string
    errors << "The value of the key :error_description is not a string" unless m[:error_description].is_a?(String)
  end # if m.is_a?(Hash)
  # 
  errors.uniq
end

Instance Method Details

#initialize(h) ⇒ Object

def self.descriptor_error(h)



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

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

#to_hashObject



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

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

#validate(output) ⇒ Object



471
472
473
474
475
476
477
478
479
# File 'lib/blackstack-deployer.rb', line 471

def validate(output)
  errors = []
  if !self.error_description.nil?
    errors << self.error_description if output.match(self.nomatch)
  else
    errors << "The output of the command matches the regular expression #{self.nomatch.inspect}" if output.match(self.nomatch)
  end
  errors
end