Sha256: cd6f040e5be0a2d45b0caeee14ddcfed4753b0a83dbc2fd64cd6a57d14b835b3
Contents?: true
Size: 961 Bytes
Versions: 3
Compression:
Stored size: 961 Bytes
Contents
module Discoverer def self.has_adapter_for? adapter_constant, the_class return false if the_class.name.nil? namespace = the_class.name.split '::' current_module = adapter_constant until namespace.empty? if RUBY_VERSION =~ /1.8/ return false unless current_module.constants.include? namespace.first else return false unless current_module.constants.include? namespace.first.to_sym end current_module = current_module.const_get namespace.shift end return true end def self.for adapter_constant, the_class the_class.ancestors.length.times do |time| if has_adapter_for? adapter_constant, the_class.ancestors[time] return eval "::#{adapter_constant}::#{the_class.ancestors[time]}" end end raise NotFoundError, "There is no #{adapter_constant.name.downcase} for #{the_class} or any of its ancestors" end class NotFoundError < StandardError; end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
discoverer-0.0.3 | lib/discoverer/discoverer.rb |
discoverer-0.0.2 | lib/discoverer/discoverer.rb |
discoverer-0.0.1 | lib/discoverer/discoverer.rb |