class MovieMasher::Service

abstraction layer for initing, upload, download, queue services

Constants

SERVICES_DIRECTORY

Attributes

__cache[RW]
__configuration[RW]

Public Class Methods

__create_service(name, kind = :queue) click to toggle source
# File lib/service.rb, line 32
def self.__create_service(name, kind = :queue)
  service = nil
  class_sym = "#{name.capitalize}#{kind.id2name.capitalize}Service".to_sym
  unless MovieMasher.const_defined?(class_sym)
    path = "#{SERVICES_DIRECTORY}/#{kind.id2name}/#{name}.rb"
    require path if File.exist?(path)
  end
  if MovieMasher.const_defined?(class_sym)
    service = MovieMasher.const_get(class_sym).new
  end
  service
end
__service(kind, type) click to toggle source
# File lib/service.rb, line 44
def self.__service(kind, type)
  Service.__cache[kind] ||= {}
  if Service.__cache[kind][type].nil?
    service = __create_service(type, kind)
    Service.__cache[kind][type] =
      if service && service.configure(Service.__configuration)
        service
      else
        false
      end
  end
  Service.__cache[kind][type]
end
__service_names(kind = :queue) click to toggle source
# File lib/service.rb, line 57
def self.__service_names(kind = :queue)
  Dir["#{SERVICES_DIRECTORY}/#{kind.id2name}/*.rb"].map do |path|
    File.basename(path, '.rb')
  end
end
configure_services(config) click to toggle source
# File lib/service.rb, line 12
def self.configure_services(config)
  Service.__configuration = config
end
downloader(type) click to toggle source
# File lib/service.rb, line 26
def self.downloader(type)
  __service(:download, type)
end
initer(type) click to toggle source
# File lib/service.rb, line 23
def self.initer(type)
  __service(:init, type)
end
queues() click to toggle source
# File lib/service.rb, line 15
def self.queues
  array = []
  __service_names(:queue).each do |type|
    service = __service(:queue, type)
    array << service if service
  end
  array
end
uploader(type) click to toggle source
# File lib/service.rb, line 29
def self.uploader(type)
  __service(:upload, type)
end

Public Instance Methods

configuration() click to toggle source
# File lib/service.rb, line 62
def configuration
  Service.__configuration
end
configure(*) click to toggle source
# File lib/service.rb, line 65
def configure(*)
  true
end