Class: DataMapper::SQLFinders::SQLParser
- Inherits:
-
Object
- Object
- DataMapper::SQLFinders::SQLParser
- Defined in:
- lib/data_mapper/sql_finders/sql_parser.rb
Instance Method Summary collapse
-
#initialize(sql) ⇒ SQLParser
constructor
A new instance of SQLParser.
- #parse ⇒ Object
Constructor Details
#initialize(sql) ⇒ SQLParser
Returns a new instance of SQLParser.
4 5 6 |
# File 'lib/data_mapper/sql_finders/sql_parser.rb', line 4 def initialize(sql) @sql = sql.dup.to_s end |
Instance Method Details
#parse ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/data_mapper/sql_finders/sql_parser.rb', line 8 def parse tokens = { :select => "SELECT", :from => "FROM", :where => "WHERE", :group_by => "GROUP BY", :having => "HAVING", :order_by => "ORDER BY", :limit_offset => "LIMIT" } parts = {} tokens.each_with_index do |(key, initial), index| parts[key] = scan_chunk(initial, tokens.values[(index + 1)..-1]) end parse_fields!(parts) parse_limit_offset!(parts) parts end |