Sha256: 387bf9213089bff9429a41c0bc2c18c895dbe5f0a7618940f5622027d7c2a820

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'facets/string/snakecase'
require 'facets/module/alias'

# This module contains the robotics adapters.  For instance, the ACME 
# Robotics adapter would be <tt>Rubot::Adapters::AcmeRobotics</tt>.  Its robot 
# class would be <tt>Rubot::Adapters::AcmeRobotics::Robot</tt>, and one can be
# created with
# 
#     fred = Rubot::Adapters::AcmeRobotics::Robot.new
# 
# or, in Rubot syntax,
# 
#     robot :fred do
#       adapter :acme_robotics
#     end
module Rubot
  # Raised when attempting to create a robot with an unrecognized adapter.
  class AdapterMissingError < Exception; end
  
  module Adapters
    class << self
      def const_missing_with_autoload(name)
        # TODO: Handle missing adapter without obscuring all LoadErrors.
        # begin
          req_name = "rubot/adapters/#{name.to_s.snakecase}"
          require req_name
          if const_defined? name
            return const_get(name)
          else
            raise AdapterMissingError, "Adapter #{name} not loaded by '#{req_name}'."
          end
        # rescue LoadError
        #   raise AdapterMissingError, "Adapter #{name} not found."
        # end
      end
      alias_method_chain :const_missing, :autoload
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Peeja-rubot-0.5.0 lib/rubot/adapters.rb