sequel 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,76 +0,0 @@
1
- # Based on great work by Sam Smoot
2
- # http://substantiality.net/archives/2007/4/16/datamapper-part-xiv-finder-block
3
-
4
- module Sequel
5
- class Dataset
6
- class BlankSlate #:nodoc:
7
- instance_methods.each { |m| undef_method m unless m =~ /^(__|instance_eval)/ }
8
- end
9
-
10
- # An Expression is made of a left side, an operator, and a right side.
11
- class Expression < BlankSlate
12
- attr_reader :left, :right
13
- attr_accessor :op
14
-
15
- def initialize(left)
16
- @left = left
17
- end
18
-
19
- def method_missing(sym, *right)
20
- @op = case sym
21
- when :==, :===, :in, :in?: :eql
22
- when :=~, :like, :like?: :like
23
- when :"<=>", :is_not: :not
24
- when :<: :lt
25
- when :<=: :lte
26
- when :>: :gt
27
- when :>=: :gte
28
- else
29
- @left = "#{left}.#{sym}"
30
- end
31
- @right = right.first
32
- self
33
- end
34
-
35
- def nil?
36
- @op = :eql
37
- @right = nil
38
- self
39
- end
40
- end
41
-
42
- # An ExpressionCompiler takes a Proc object and compiles it
43
- # into an array of expressions using instance_eval magic.
44
- class ExpressionCompiler < BlankSlate
45
- def initialize(&block) #:nodoc:
46
- @block = block
47
- @expressions = []
48
- end
49
-
50
- # Converts the block into an array of expressions.
51
- def __to_a__
52
- instance_eval(&@block)
53
- @expressions
54
- rescue => e
55
- raise SequelError, e.message
56
- end
57
-
58
- private
59
- def __expr(sym) #:nodoc:
60
- expr = Expression.new(sym)
61
- @expressions << expr
62
- expr
63
- end
64
-
65
- def method_missing(sym, *args); __expr(sym); end #:nodoc:
66
- def test; __expr(:test); end #:nodoc:
67
- def SUM(sym); __expr(sym.SUM); end #:nodoc:
68
- end
69
- end
70
- end
71
-
72
- class Proc
73
- def to_expressions
74
- Sequel::Dataset::ExpressionCompiler.new(&self).__to_a__
75
- end
76
- end