Class: Cyrel::Clause::Limit

Inherits:
Base
  • Object
show all
Defined in:
lib/cyrel/clause/limit.rb

Overview

Represents a LIMIT clause in a Cypher query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(amount) ⇒ Limit

Initializes a LIMIT clause.

Parameters:

  • amount (Integer, Cyrel::Expression::Base, Object)

    The maximum number of results to return. Can be an integer literal or an expression that evaluates to an integer (typically a parameter).



13
14
15
16
# File 'lib/cyrel/clause/limit.rb', line 13

def initialize(amount)
  @amount = Expression.coerce(amount)
  # Could add validation here.
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



7
8
9
# File 'lib/cyrel/clause/limit.rb', line 7

def amount
  @amount
end

Instance Method Details

#render(query) ⇒ String

Renders the LIMIT clause.

Parameters:

  • query (Cyrel::Query)

    The query object for rendering the amount expression.

Returns:

  • (String)

    The Cypher string fragment for the clause.



21
22
23
# File 'lib/cyrel/clause/limit.rb', line 21

def render(query)
  "LIMIT #{@amount.render(query)}"
end

#replace!(other_limit) ⇒ Object

Merging LIMIT typically replaces the existing value.

Parameters:



27
28
29
30
# File 'lib/cyrel/clause/limit.rb', line 27

def replace!(other_limit)
  @amount = other_limit.amount
  self
end