class Souffle::Node::RunListParser
The runlist parser singleton.
Constants
- PARSER
The runlist match parser
Public Class Methods
Checks whether the runlist_hash is a valid word.
@param [ Hash ] runlist_hash The runlist hash to test.
@raise [ InvalidRunlistName ] Runlist Name is invalid.
# File lib/souffle/node/runlist_parser.rb, line 62 def gaurentee_name_is_word(runlist_hash) m = /[A-Za-z0-9_\-:]+/ unless m.match(runlist_hash["name"])[0] == runlist_hash["name"] raise Souffle::Exceptions::InvalidRunlistName, "Name must be [A-Za-z0-9_-:]." end end
Tests whether the runlist_hash name and type are valid.
@param [ Hash ] runlist_hash The runlist hash to test.
@raise [ InvalidRunlistName, InvalidRunlistType ] Raises exceptions when the runlist match failed, the type wasn't a recipe or role, or when the name itself isn't a valid word.
# File lib/souffle/node/runlist_parser.rb, line 42 def gaurentee_valid_keys(runlist_hash) if runlist_hash.nil? raise Souffle::Exceptions::InvalidRunlistType, "Type must be one of (role|recipe)" end if runlist_hash["name"].nil? or runlist_hash["name"].empty? raise Souffle::Exceptions::InvalidRunlistName, "Name cannot be nil or empty." end if runlist_hash["type"].nil? or runlist_hash["type"].empty? raise Souffle::Exceptions::InvalidRunlistType, "Type cannot be nil or empty and must be one of (role|recipe)" end end
Takes the matches and converts them into a hashed version.
@param [ MatchData,NilClass ] match The MatchData to hashify.
@return [ Hash,NilClass ] The hashified version of the runlist item.
# File lib/souffle/node/runlist_parser.rb, line 30 def hashify_match(match) return nil if match.nil? Hash[*match.names.zip(match.captures).flatten] end
Checks to see whether the runlist item is a valid recipe or role.
@param [ String ] item The runlist item.
@return [ Hash ] The runlist item as a hash.
# File lib/souffle/node/runlist_parser.rb, line 18 def parse(item) runlist_hash = hashify_match(PARSER.match(item)) gaurentee_valid_keys(runlist_hash) gaurentee_name_is_word(runlist_hash) runlist_hash end