Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def notify(path, hash={})
- # Split the path string into an array
- path = path.to_s.split(' ')
- # Find the error message by looping through the path and building an array
- message = NOTIFICATIONS
- path.each do |attribute|
- message = message[attribute.to_sym]
- end
- # Throw an exception if no message is found
- throw "Unable to find notification message" if message.nil?
- # Scan the message for any variables and throw an exception if they aren't in the hash
- message.scan(/::(.*?)::/) do |match|
- match = match.to_s.to_sym
- throw ":#{match} is a required attribute" unless hash.include?(match)
- end
- # Loop through the hash and replace the appropriate variables in the message string
- hash.each do |index, value|
- message.gsub!(/::#{index}::/, value)
- end
- return message
- end
Add Comment
Please, Sign In to add comment