Sha256: 4e2a047616b79f4d409b85592e13fff70c19f3db27e981c8b5f2686f93d2e140

Contents?: true

Size: 1.04 KB

Versions: 6

Compression:

Stored size: 1.04 KB

Contents

module HackBoxen

  class ConfigValidator

    # This makes sure the "requires" are met by the "provides"
    # in the hackbox config. Failures are stored in <tt>fails</tt>.
    def self.failed_requirements
      p = WorkingConfig['provides']
      r = WorkingConfig['requires']
      fails = []
      if r != nil
        if not r.class == Hash  or not p.class == Hash
          fails << "'requires' and 'provides' must be Hash"
        else
          fails += self.match_requirements r, p
        end
      end
      fails
    end

    # Recursive. r and p must be hashes.
    def self.match_requirements r,p,path=""
      fails = []
      r.keys.each { |k|
        if not p.has_key? k
          fails << "Missing #{path}/#{k}"
        else
          if r[k].class == Hash
            if p[k].class != Hash
              fails << "'provides' #{path}/#{k} should be a hash because 'requires' is."
            else
              fails += self.match_requirements r[k],p[k],"#{path}/#{k}"
            end
          end
        end
      }
      fails
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hackboxen-0.1.5 lib/hackboxen/utils/config_validator.rb
hackboxen-0.1.4 lib/hackboxen/utils/config_validator.rb
hackboxen-0.1.3 lib/hackboxen/utils/config_validator.rb
hackboxen-0.1.2 lib/hackboxen/utils/config_validator.rb
hackboxen-0.1.1 lib/hackboxen/utils/config_validator.rb
hackboxen-0.1.0 lib/hackboxen/utils/config_validator.rb