Class: Flydata::Parser::ParserProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/parser/parser_provider.rb

Constant Summary collapse

@@mutex =
Mutex.new
@@parsers =
{}

Class Method Summary collapse

Class Method Details

.parser(db_type, parser_type) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/flydata/parser/parser_provider.rb', line 12

def self.parser(db_type, parser_type)
  key = [db_type.to_s, parser_type.to_s].join("::").to_s
  @@mutex.synchronize do
    if @@parsers[key]
      return @@parsers[key]
    else
      # lazy load
      treetop_path = File.expand_path(
           "../source_#{db_type}/parser/#{parser_type}.treetop",
           File.dirname(__FILE__))
      Treetop.load treetop_path
      @@parsers[key] = "#{parser_type}_parser".camelize.constantize
    end
  end
end