Class: Predicate::ToSequel
- Inherits:
-
Sexpr::Processor
- Object
- Sexpr::Processor
- Predicate::ToSequel
- Defined in:
- lib/predicate/sequel/to_sequel.rb
Instance Method Summary collapse
- #on_and(sexpr) ⇒ Object
- #on_contradiction(sexpr) ⇒ Object
- #on_dyadic_comp(sexpr) ⇒ Object (also: #on_lt, #on_lte, #on_gt, #on_gte)
- #on_eq(sexpr) ⇒ Object
- #on_identifier(sexpr) ⇒ Object
- #on_in(sexpr) ⇒ Object
- #on_literal(sexpr) ⇒ Object
- #on_native(sexpr) ⇒ Object
- #on_neq(sexpr) ⇒ Object
- #on_not(sexpr) ⇒ Object
- #on_or(sexpr) ⇒ Object
- #on_qualified_identifier(sexpr) ⇒ Object
- #on_tautology(sexpr) ⇒ Object
Instance Method Details
#on_and(sexpr) ⇒ Object
54 55 56 57 |
# File 'lib/predicate/sequel/to_sequel.rb', line 54 def on_and(sexpr) body = sexpr.sexpr_body body[1..-1].inject(apply(body.first)){|f,t| f & apply(t) } end |
#on_contradiction(sexpr) ⇒ Object
22 23 24 |
# File 'lib/predicate/sequel/to_sequel.rb', line 22 def on_contradiction(sexpr) ::Sequel::SQL::BooleanConstant.new(false) end |
#on_dyadic_comp(sexpr) ⇒ Object Also known as: on_lt, on_lte, on_gt, on_gte
36 37 38 39 |
# File 'lib/predicate/sequel/to_sequel.rb', line 36 def on_dyadic_comp(sexpr) left, right = apply(sexpr.left), apply(sexpr.right) left.send(sexpr.operator_symbol, right) end |
#on_eq(sexpr) ⇒ Object
26 27 28 29 |
# File 'lib/predicate/sequel/to_sequel.rb', line 26 def on_eq(sexpr) left, right = apply(sexpr.left), apply(sexpr.right) ::Sequel.expr(left => right) end |
#on_identifier(sexpr) ⇒ Object
4 5 6 |
# File 'lib/predicate/sequel/to_sequel.rb', line 4 def on_identifier(sexpr) ::Sequel.identifier(sexpr.last) end |
#on_in(sexpr) ⇒ Object
45 46 47 48 |
# File 'lib/predicate/sequel/to_sequel.rb', line 45 def on_in(sexpr) left, right = apply(sexpr.identifier), sexpr.last ::Sequel.expr(left => right) end |
#on_literal(sexpr) ⇒ Object
12 13 14 |
# File 'lib/predicate/sequel/to_sequel.rb', line 12 def on_literal(sexpr) sexpr.last.nil? ? nil : ::Sequel.expr(sexpr.last) end |
#on_native(sexpr) ⇒ Object
64 65 66 |
# File 'lib/predicate/sequel/to_sequel.rb', line 64 def on_native(sexpr) raise NotSupportedError end |
#on_neq(sexpr) ⇒ Object
31 32 33 34 |
# File 'lib/predicate/sequel/to_sequel.rb', line 31 def on_neq(sexpr) left, right = apply(sexpr.left), apply(sexpr.right) ~::Sequel.expr(left => right) end |
#on_not(sexpr) ⇒ Object
50 51 52 |
# File 'lib/predicate/sequel/to_sequel.rb', line 50 def on_not(sexpr) ~apply(sexpr.last) end |
#on_or(sexpr) ⇒ Object
59 60 61 62 |
# File 'lib/predicate/sequel/to_sequel.rb', line 59 def on_or(sexpr) body = sexpr.sexpr_body body[1..-1].inject(apply(body.first)){|f,t| f | apply(t) } end |
#on_qualified_identifier(sexpr) ⇒ Object
8 9 10 |
# File 'lib/predicate/sequel/to_sequel.rb', line 8 def on_qualified_identifier(sexpr) ::Sequel.as(sexpr.qualifier, sexpr.name) end |
#on_tautology(sexpr) ⇒ Object
18 19 20 |
# File 'lib/predicate/sequel/to_sequel.rb', line 18 def on_tautology(sexpr) ::Sequel::SQL::BooleanConstant.new(true) end |