Class: Mysql::ParserProvider

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.parser(db_type, parser_type) ⇒ Object


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

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.join(
        File.expand_path(File.dirname(__FILE__)),
        "parser/#{db_type}/#{parser_type}.treetop")
      Treetop.load treetop_path
      @@parsers[key] = "#{parser_type}_parser".camelize.constantize
    end
  end
end