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.



468
469
470
# File 'lib/blackstack-deployer.rb', line 468

def error_description
  @error_description
end

#nomatchObject

Returns the value of attribute nomatch.



468
469
470
# File 'lib/blackstack-deployer.rb', line 468

def nomatch
  @nomatch
end

Class Method Details

.descriptor_errors(m) ⇒ Object



470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/blackstack-deployer.rb', line 470

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)



489
490
491
492
493
494
# File 'lib/blackstack-deployer.rb', line 489

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



496
497
498
499
500
501
# File 'lib/blackstack-deployer.rb', line 496

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

#validate(output) ⇒ Object



503
504
505
506
507
508
509
510
511
# File 'lib/blackstack-deployer.rb', line 503

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