Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. module GoggleBox
  2. # require 'httparty'
  3.  
  4. module TVRage
  5. class Show
  6. def self.search opts={}
  7. "searching TVRage for shows with options #{opts.inspect}"
  8. end
  9. end
  10. end
  11.  
  12. module TheTVDB
  13. class Show
  14. def self.search opts={}
  15. "searching TheTVDB for shows with options #{opts.inspect}"
  16. end
  17. end
  18. end
  19.  
  20. class << self
  21. attr_writer :adapter
  22. def adapter
  23. @adapter ||= GoggleBox::TVRage
  24. end
  25. end
  26.  
  27. # Bit o' metaprogramming magic to invoke the right class on the adapter
  28. # Raises a normal NameError if the constant is missing
  29. def self.const_missing klass
  30. GoggleBox::adapter.const_get(klass)
  31. end
  32.  
  33. end
  34.  
  35. GoggleBox.adapter # => GoggleBox::TVRage
  36. GoggleBox::Show.search :title => "foo" # => "searching TVRage for shows with options {:title=>\"foo\"}"
  37.  
  38. GoggleBox.adapter = GoggleBox::TheTVDB
  39. GoggleBox.adapter # => GoggleBox::TheTVDB
  40. GoggleBox::Show.search :title => "foo" # => "searching TheTVDB for shows with options {:title=>\"foo\"}"
Add Comment
Please, Sign In to add comment