Skip to content

Commit 6c8cfbb

Browse files
committed
Added VERSION constant, and removed class loading based on const_missing and use simple requires instead.
1 parent ec2c4e1 commit 6c8cfbb

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

lib/sql_tree.rb

+7-29
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# necessary files for the gem to function properly.
66
module SQLTree
77

8+
VERSION = "0.1.1"
9+
810
class << self
911
# The character to quote variable names with.
1012
attr_accessor :identifier_quote_char
@@ -13,38 +15,14 @@ class << self
1315
# Set default quote characters
1416
self.identifier_quote_char = '"'
1517

16-
# Loads constants in the SQLTree namespace using self.load_default_class_file(base, const)
17-
# <tt>const</tt>:: The constant that is not yet loaded in the SQLTree namespace. This should be passed as a string or symbol.
18-
def self.const_missing(const)
19-
load_default_class_file(SQLTree, const)
20-
end
21-
22-
# Loads constants that reside in the SQLTree tree using the constant name
23-
# and its base constant to determine the filename.
24-
# <tt>base</tt>:: The base constant to load the constant from. This should be Foo when the constant Foo::Bar is being loaded.
25-
# <tt>const</tt>:: The constant to load from the base constant as a string or symbol. This should be 'Bar' or :Bar when the constant Foo::Bar is being loaded.
26-
def self.load_default_class_file(base, const)
27-
require "#{to_underscore("#{base.name}::#{const}")}"
28-
base.const_get(const) if base.const_defined?(const)
29-
end
30-
3118
# The <tt>[]</tt> method is a shorthand for the <tt>SQLTree::Parser.parse</tt>
3219
# method to parse an SQL query and return a SQL syntax tree.
3320
def self.[](query, options = {})
3421
SQLTree::Parser.parse(query)
3522
end
36-
37-
# Convert a string/symbol in camelcase (SQLTree::Parser) to underscores (sql_tree/parser)
38-
# This function can be used to load the file (using require) in which the given constant is defined.
39-
# <tt>str</tt>:: The string to convert in the following format: <tt>ModuleName::ClassName</tt>
40-
def self.to_underscore(str)
41-
str.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
42-
end
43-
44-
# Convert a string/symbol in underscores (<tt>sql_tree/parser</tt>) to camelcase
45-
# (<tt>SqlTree::Parser</tt>). This can be used to find the class that is defined in a given filename.
46-
# <tt>str</tt>:: The string to convert in the following format: <tt>module_name/class_name</tt>
47-
def self.to_camelcase(str)
48-
str.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
49-
end
5023
end
24+
25+
require 'sql_tree/token'
26+
require 'sql_tree/tokenizer'
27+
require 'sql_tree/node'
28+
require 'sql_tree/parser'

lib/sql_tree/node.rb

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
module SQLTree::Node
22

3-
# Auto-loades files for Node subclasses that reside in the
4-
# node directory, based on the classname.
5-
def self.const_missing(const)
6-
SQLTree.load_default_class_file(SQLTree::Node, const)
7-
end
8-
93
# The SQLTree::Node::Base class is the superclass for all node
104
# types that are used to represent SQL queries.
115
#
@@ -105,4 +99,22 @@ def self.[](sql, options = {})
10599
self.parse(parser)
106100
end
107101
end
108-
end
102+
end
103+
104+
require 'sql_tree/node/expression'
105+
106+
require 'sql_tree/node/select_query'
107+
require 'sql_tree/node/select_declaration'
108+
require 'sql_tree/node/table_reference'
109+
require 'sql_tree/node/source'
110+
require 'sql_tree/node/join'
111+
require 'sql_tree/node/ordering'
112+
113+
require 'sql_tree/node/insert_query'
114+
require 'sql_tree/node/update_query'
115+
require 'sql_tree/node/delete_query'
116+
require 'sql_tree/node/set_query'
117+
118+
require 'sql_tree/node/begin_statement'
119+
require 'sql_tree/node/commit_statement'
120+
require 'sql_tree/node/rollback_statement'

lib/sql_tree/token.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def inspect # :nodoc:
145145
# A list of all the SQL reserverd keywords.
146146
KEYWORDS = %w{SELECT FROM WHERE GROUP HAVING ORDER DISTINCT LEFT RIGHT INNER FULL OUTER NATURAL JOIN USING
147147
AND OR NOT AS ON IS NULL BY LIKE ILIKE BETWEEN IN ASC DESC INSERT INTO VALUES DELETE UPDATE
148-
SET BEGIN COMMIT TO INTERVAL}
148+
SET BEGIN COMMIT ROLLBACK TO INTERVAL COUNT}
149149

150150
# Create a token for all the reserved keywords in SQL
151151
KEYWORDS.each { |kw| const_set(kw, Class.new(SQLTree::Token::Keyword)) }

0 commit comments

Comments
 (0)