Module: Pendaxes::Finder

Included in:
Detector, Notificator, Reporter
Defined in:
lib/pendaxes/finder.rb

Instance Method Summary collapse

Instance Method Details

#announce(name, klass) ⇒ Object



25
26
27
# File 'lib/pendaxes/finder.rb', line 25

def announce(name, klass)
  (@finder_cache ||= {})[name] = klass
end

#find(name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pendaxes/finder.rb', line 3

def find(name)
  @finder_cache ||= {}
  path = case name
         when String
           name
         when Symbol
           "#{@finder_prefix || ""}#{name}"
         else
           raise ArgumentError, "name should be a kind of String or Symbol"
         end
  return @finder_cache[name] if @finder_cache[name]
  require path
  announce name, @finder_latest_inherited
end

#inherited(klass) ⇒ Object



18
19
20
21
22
23
# File 'lib/pendaxes/finder.rb', line 18

def inherited(klass)
  if klass.name
    announce klass.name.gsub(/^.*::/,'').gsub(/.[A-Z]/){|s| s[0]+"_"+s[1] }.downcase.to_sym, klass
  end
  @finder_latest_inherited = klass
end