-
-
Save paulingham/760497 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module GoggleBox | |
# require 'httparty' | |
module TVRage | |
class Show | |
def self.search opts={} | |
"searching TVRage for shows with options #{opts.inspect}" | |
end | |
end | |
end | |
module TheTVDB | |
class Show | |
def self.search opts={} | |
"searching TheTVDB for shows with options #{opts.inspect}" | |
end | |
end | |
end | |
class << self | |
attr_writer :adapter | |
def adapter | |
@adapter ||= GoggleBox::TVRage | |
end | |
end | |
# Bit o' metaprogramming magic to invoke the right class on the adapter | |
# Raises a normal NameError if the constant is missing | |
def self.const_missing klass | |
GoggleBox::adapter.const_get(klass) | |
end | |
end | |
GoggleBox.adapter # => GoggleBox::TVRage | |
GoggleBox::Show.search :title => "foo" # => "searching TVRage for shows with options {:title=>\"foo\"}" | |
GoggleBox.adapter = GoggleBox::TheTVDB | |
GoggleBox.adapter # => GoggleBox::TheTVDB | |
GoggleBox::Show.search :title => "foo" # => "searching TheTVDB for shows with options {:title=>\"foo\"}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment