Guest User

Untitled

a guest
Apr 25th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. def notify(path, hash={})
  2. # Split the path string into an array
  3. path = path.to_s.split(' ')
  4.  
  5. # Find the error message by looping through the path and building an array
  6. message = NOTIFICATIONS
  7. path.each do |attribute|
  8. message = message[attribute.to_sym]
  9. end
  10. # Throw an exception if no message is found
  11. throw "Unable to find notification message" if message.nil?
  12.  
  13. # Scan the message for any variables and throw an exception if they aren't in the hash
  14. message.scan(/::(.*?)::/) do |match|
  15. match = match.to_s.to_sym
  16. throw ":#{match} is a required attribute" unless hash.include?(match)
  17. end
  18.  
  19. # Loop through the hash and replace the appropriate variables in the message string
  20. hash.each do |index, value|
  21. message.gsub!(/::#{index}::/, value)
  22. end
  23.  
  24. return message
  25. end
Add Comment
Please, Sign In to add comment