Sha256: 0143f01b05ba1e692810a39de3ca4bcfed4227674180f00816bb2f4ae4a64a97

Contents?: true

Size: 877 Bytes

Versions: 2

Compression:

Stored size: 877 Bytes

Contents

module SQLTree::Node

  def self.const_missing(const)
    SQLTree.load_default_class_file(SQLTree::Node, const)
  end

  class Base

    # Pretty prints this instance for inspection
    def inspect
      "#{self.class.name}[#{self.to_sql}]"
    end

    # Quotes a variable name so that it can be safely used within
    # SQL queries.
    def quote_var(name)
      "\"#{name}\""
    end

    # Quotes a string so that it can be used within an SQL query.
    def quote_str(str)
      "'#{str.gsub(/\'/, "''")}'"
    end

    # This method should be implemented by a subclass.
    def self.parse(tokens)
      raise 'Only implemented in subclasses!'
    end

    # Parses a string, expecting it to be parsable to an instance of
    # the current class.
    def self.[](sql, options = {})
      parser = SQLTree::Parser.new(sql, options)
      self.parse(parser)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sql_tree-0.1.0 lib/sql_tree/node.rb
sql_tree-0.0.3 lib/sql_tree/node.rb