lib/fauna/query.rb in fauna-2.0.0 vs lib/fauna/query.rb in fauna-2.1.0
- old
+ new
@@ -41,12 +41,16 @@
##
# Construct a ref value
#
# Reference: {FaunaDB Values}[https://faunadb.com/documentation/queries#values]
- def ref(*args)
- Ref.new(*args)
+ def ref(str, id = nil)
+ if id.nil?
+ Ref.new(str)
+ else
+ Expr.new ref: Expr.wrap(str), id: Expr.wrap(id)
+ end
end
##
# An object expression
#
@@ -132,10 +136,11 @@
# +block+::
# Takes one or more #var expressions and uses them to construct an expression.
# If this takes more than one argument, the lambda destructures an array argument.
# (To destructure single-element arrays use #lambda_expr.)
def lambda(&block)
+ dsl = Query::QueryDSLContext.new
vars =
block.parameters.map do |kind, name|
fail ArgumentError, 'Splat parameters are not supported in lambda expressions.' if kind == :rest
name
end
@@ -143,13 +148,13 @@
case vars.length
when 0
fail ArgumentError, 'Block must take at least 1 argument.'
when 1
# When there's only 1 parameter, don't use an array pattern.
- lambda_expr vars[0], block.call(var(vars[0]))
+ lambda_expr vars[0], DSLContext.eval_dsl(dsl, var(vars[0]), &block)
else
- lambda_expr vars, block.call(*(vars.map { |v| var(v) }))
+ lambda_expr vars, DSLContext.eval_dsl(dsl, *(vars.map { |v| var(v) }), &block)
end
end
##
# A raw lambda expression
@@ -440,10 +445,18 @@
end
# :section: Miscellaneous Functions
##
+ # A next_id function
+ #
+ # Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation#queries-misc_functions]
+ def next_id
+ Expr.new next_id: nil
+ end
+
+ ##
# An equals function
#
# Reference: {FaunaDB Miscellaneous Functions}[https://faunadb.com/documentation#queries-misc_functions]
def equals(*values)
Expr.new equals: Expr.wrap_varargs(values)
@@ -572,9 +585,16 @@
def to_s
"Expr(#{@raw})"
end
alias_method :inspect, :to_s
+
+ def ==(other)
+ return false unless other.is_a? Expr
+ raw == other.raw
+ end
+
+ alias_method :eql?, :==
def self.wrap(obj)
if obj.is_a? Expr
obj
elsif obj.is_a? Proc