Skip to content

Commit

Permalink
WIP comments
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jan 8, 2013
1 parent 38d0a22 commit 7597f99
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/arel/nodes/node.rb
Expand Up @@ -3,6 +3,8 @@ module Nodes
###
# Abstract base class for all AST nodes
class Node
attr_accessor :comment

include Arel::FactoryMethods
include Enumerable

Expand Down
6 changes: 6 additions & 0 deletions lib/arel/select_manager.rb
Expand Up @@ -254,6 +254,12 @@ def joins manager
manager.join_sql
end

def comment comment
@ast.comment ||= []
@ast.comment << comment
self
end

class Row < Struct.new(:data) # :nodoc:
def id
data['id']
Expand Down
4 changes: 3 additions & 1 deletion lib/arel/tree_manager.rb
Expand Up @@ -18,7 +18,9 @@ def visitor
end

def to_sql
visitor.accept @ast
sql = visitor.accept ast
sql << " /* #{ast.comment.join(" ")} */" if ast.comment
sql
end

def initialize_copy other
Expand Down
14 changes: 14 additions & 0 deletions test/test_select_manager.rb
Expand Up @@ -1155,5 +1155,19 @@ def test_join_sources
manager.ast.cores.last.set_quantifier.must_equal nil
end
end

describe 'comment' do
it 'makes sql' do
manager = Arel::SelectManager.new Table.engine
manager.comment("XXX")
manager.to_sql.must_be_like 'SELECT /* XXX */'
end

it 'makes sql chains' do
manager = Arel::SelectManager.new Table.engine
manager.comment("XXX").comment("YYY")
manager.to_sql.must_be_like 'SELECT /* XXX YYY */'
end
end
end
end

0 comments on commit 7597f99

Please sign in to comment.