Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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\"}"
Add Comment
Please, Sign In to add comment