Module: Discoverer
- Defined in:
- lib/discoverer/model.rb,
lib/discoverer/reader.rb,
lib/discoverer/writer.rb,
lib/discoverer/pattern.rb,
lib/discoverer/version.rb,
lib/discoverer/discoverer.rb
Defined Under Namespace
Modules: Reader, Writer
Classes: Model, NotFoundError, Pattern
Constant Summary
collapse
- VERSION =
"0.0.3"
Class Method Summary
collapse
Class Method Details
.for(adapter_constant, the_class) ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/discoverer/discoverer.rb', line 17
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
|
.has_adapter_for?(adapter_constant, the_class) ⇒ Boolean
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/discoverer/discoverer.rb', line 2
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
|