Class: Souffle::Node::RunListParser
- Inherits:
-
Object
- Object
- Souffle::Node::RunListParser
- Defined in:
- lib/souffle/node/runlist_parser.rb
Overview
The runlist parser singleton.
Constant Summary collapse
- PARSER =
The runlist match parser
%r{ (?<type> (recipe|role)) {0} # The runlist item type. (?<name> (.*)) {0} # The runlist item name. \g<type>\[\g<name>\] }x
Class Method Summary collapse
-
.gaurentee_name_is_word(runlist_hash) ⇒ Object
Checks whether the runlist_hash is a valid word.
-
.gaurentee_valid_keys(runlist_hash) ⇒ Object
Tests whether the runlist_hash name and type are valid.
-
.hashify_match(match) ⇒ Hash, NilClass
Takes the matches and converts them into a hashed version.
-
.parse(item) ⇒ Hash
Checks to see whether the runlist item is a valid recipe or role.
Class Method Details
.gaurentee_name_is_word(runlist_hash) ⇒ Object
Checks whether the runlist_hash is a valid word.
62 63 64 65 66 67 68 |
# 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 |
.gaurentee_valid_keys(runlist_hash) ⇒ Object
Tests whether the runlist_hash name and type are valid.
when the runlist match failed, the type wasn’t a recipe or role, or when the name itself isn’t a valid word.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
.hashify_match(match) ⇒ Hash, NilClass
Takes the matches and converts them into a hashed version.
30 31 32 33 |
# 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 |
.parse(item) ⇒ Hash
Checks to see whether the runlist item is a valid recipe or role.
18 19 20 21 22 23 |
# 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 |