Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. class ContactsManager
  2. def initialize(debug)
  3. @debug = debug
  4. @load = false
  5. @contacts = []
  6. @personalcontacts = []
  7. end
  8.  
  9. attr_reader :contacts
  10. attr_reader :personalcontacts
  11.  
  12. def loaded?
  13. !@load
  14. end
  15.  
  16. def run_queue
  17. load_contacts
  18. end
  19.  
  20. def load_contactsmanager_contacts
  21. @load = true
  22. end
  23.  
  24. private
  25.  
  26. def load_contacts
  27. return unless @load
  28. @contacts = safe_load_yaml('./scripts/data/base-contacts.yaml')
  29. @contacts = contacts['contacts']
  30. @personalcontacts = safe_load_yaml('./scripts/profiles/Syntych-contacts.yaml')
  31. @personalcontacts = personalcontacts['contacts']
  32. @contacts = contacts.merge!(personalcontacts)
  33. @load = false
  34. end
  35.  
  36. def safe_load_yaml(path)
  37. YAML.load_file(path)
  38. rescue => e
  39. echo('*** ERROR PARSING YAML FILE ***')
  40. echo(e.message)
  41. return []
  42. end
  43. end
  44.  
  45. ----------------------------------------
  46.  
  47. $contactsmanager = ContactsManager.new(debug)
  48.  
  49. ------------------------------------------
  50.  
  51. def load_contactsmanager_contacts
  52. $contactsmanager.load_contactsmanager_contacts
  53. pause 0.1 until $contactsmanager.loaded?
  54. $contactsmanager.contacts
  55. end
  56.  
  57. ------------------------------------------------
  58.  
  59. $contactsmanager.run_queue
  60.  
  61. ===========================================================
  62.  
  63.  
  64. contacts = load_contactsmanager_contacts
  65. echo contacts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement