Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Load private docs in .yardopts, and fix quoting for Predicates in Pre…

…dicateVisitor
  • Loading branch information...
commit 3415532e989e62375feda2d37a83bba932d36ff9 1 parent 9b1efe4
Ernie Miller authored April 28, 2011
4  .yardopts
... ...
@@ -1,3 +1,3 @@
1 1
 --main README.md
2  
---no-private
3  
---exclude compat
  2
+--private
  3
+--exclude compat
13  lib/squeel/dsl.rb
@@ -34,10 +34,23 @@ def self.eval(&block)
34 34
 
35 35
     private
36 36
 
  37
+    # This isn't normally called directly, but via DSL.eval, which will
  38
+    # pass the block's binding to the new instance, for use with #my.
  39
+    #
  40
+    # @param [Binding] The block's binding.
37 41
     def initialize(caller_binding)
38 42
       @caller = caller_binding.eval 'self'
39 43
     end
40 44
 
  45
+    # If you really need to get at an instance variable or method inside
  46
+    # a DSL block, this method will let you do it. It passes a block back
  47
+    # to the DSL's caller for instance_eval.
  48
+    #
  49
+    # It's also pretty evil, so I hope you enjoy using it while I'm burning in
  50
+    # programmer hell.
  51
+    #
  52
+    # @param &block A block to instance_eval against the DSL's caller.
  53
+    # @return
41 54
     def my(&block)
42 55
       @caller.instance_eval &block
43 56
     end
16  lib/squeel/visitors/attribute_visitor.rb
@@ -120,6 +120,16 @@ def visit_Squeel_Nodes_Order(o, parent)
120 120
       # Visit a Function node. Each function argument will be accepted or
121 121
       # contextualized if appropriate. Keep in mind that this occurs with
122 122
       # the current parent within the context.
  123
+      #
  124
+      # @example A function as the endpoint of a keypath
  125
+      #   Person.joins{children}.order{children.coalesce(name, '<no name>')}
  126
+      #   # => SELECT "people".* FROM "people"
  127
+      #          INNER JOIN "people" "children_people"
  128
+      #            ON "children_people"."parent_id" = "people"."id"
  129
+      #          ORDER BY coalesce("children_people"."name", '<no name>')
  130
+      #
  131
+      # @param [Nodes::Function] o The function node to visit
  132
+      # @param parent The node's parent within the context
123 133
       def visit_Squeel_Nodes_Function(o, parent)
124 134
         args = o.args.map do |arg|
125 135
           case arg
@@ -134,6 +144,12 @@ def visit_Squeel_Nodes_Function(o, parent)
134 144
         Arel::Nodes::NamedFunction.new(o.name, args, o.alias)
135 145
       end
136 146
 
  147
+      # Visit an Operation node. Each operand will be accepted or
  148
+      # contextualized if appropriate. Keep in mind that this occurs with
  149
+      # the current parent within the context.
  150
+      #
  151
+      # @param [Nodes::Operation] o The operation node to visit
  152
+      # @param parent The node's parent within the context
137 153
       def visit_Squeel_Nodes_Operation(o, parent)
138 154
         args = o.args.map do |arg|
139 155
           case arg
1  lib/squeel/visitors/base.rb
@@ -40,6 +40,7 @@ def self.can_accept?(object)
40 40
 
41 41
       private
42 42
 
  43
+      # A hash that caches the method name to use for a visitor for a given class
43 44
       DISPATCH = Hash.new do |hash, klass|
44 45
         hash[klass] = "visit_#{klass.name.gsub('::', '_')}"
45 46
       end
4  lib/squeel/visitors/predicate_visitor.rb
@@ -47,8 +47,10 @@ def visit_Squeel_Nodes_Predicate(o, parent)
47 47
         end
48 48
 
49 49
         case o.expr
50  
-        when Nodes::Function, Nodes::Stub
  50
+        when Nodes::Stub
51 51
           accept(o.expr, parent).send(o.method_name, value)
  52
+        when Nodes::Function
  53
+          accept(o.expr, parent).send(o.method_name, quote(value))
52 54
         else
53 55
           contextualize(parent)[o.expr].send(o.method_name, value)
54 56
         end
7  spec/squeel/adapters/active_record/relation_spec.rb
@@ -190,7 +190,7 @@ module ActiveRecord
190 190
         end
191 191
 
192 192
         describe '#to_sql' do
193  
-          it 'casts a non-acceptable value for a Function properly' do
  193
+          it 'casts a non-acceptable value for a Function key properly in a hash' do
194 194
             relation = Person.joins(:children).where(:children => {:coalesce.func(:name, 'Mr. No-name') => 'Ernie'})
195 195
             relation.to_sql.should match /'Ernie'/
196 196
           end
@@ -209,6 +209,11 @@ module ActiveRecord
209 209
             relation = Person.joins(:children).where{{children.coalesce(:name, 'Mr. No-name').eq => 'Ernie'}}
210 210
             relation.to_sql.should match /'Ernie'/
211 211
           end
  212
+
  213
+          it 'casts a non-acceptable value for a Function with a Predicate endpoint containing a Function expr properly' do
  214
+            relation = Person.joins(:children).where{children.coalesce(:name, 'Mr. No-name') == 'Ernie'}
  215
+            relation.to_sql.should match /'Ernie'/
  216
+          end
212 217
         end
213 218
 
214 219
         describe '#includes' do

0 notes on commit 3415532

Please sign in to comment.
Something went wrong with that request. Please try again.