Skip to content

Instantly share code, notes, and snippets.

@paulingham
Forked from caius/gist:760454
Created December 30, 2010 23:49
Show Gist options
  • Save paulingham/760497 to your computer and use it in GitHub Desktop.
Save paulingham/760497 to your computer and use it in GitHub Desktop.
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