Class: NoSE::Plans::LimitPlanStep

Inherits:
PlanStep show all
Defined in:
lib/nose/plans/limit.rb

Overview

Limit results from a previous lookup This should only ever occur at the end of a plan

Instance Attribute Summary collapse

Attributes inherited from PlanStep

#children, #cost, #fields, #parent, #state

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PlanStep

#add_fields_from_index, #calculate_cost, inherited, #parent_index, #parent_steps, #to_color

Methods included from Supertype

included

Constructor Details

#initialize(limit, state = nil) ⇒ LimitPlanStep

Returns a new instance of LimitPlanStep.



10
11
12
13
14
15
16
17
# File 'lib/nose/plans/limit.rb', line 10

def initialize(limit, state = nil)
  super()
  @limit = limit

  return if state.nil?
  @state = state.dup
  @state.cardinality = @limit
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



8
9
10
# File 'lib/nose/plans/limit.rb', line 8

def limit
  @limit
end

Class Method Details

.apply(_parent, state) ⇒ LimitPlanStep

Check if we can apply a limit

Returns:



31
32
33
34
35
36
37
38
39
# File 'lib/nose/plans/limit.rb', line 31

def self.apply(_parent, state)
  # TODO: Apply if have IDs of the last entity set
  #       with no filter/sort needed

  return nil if state.query.limit.nil?
  return nil unless state.answered? check_limit: false

  LimitPlanStep.new state.query.limit, state
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Two limit steps are equal if they have the same value for the limit



20
21
22
# File 'lib/nose/plans/limit.rb', line 20

def ==(other)
  other.instance_of?(self.class) && @limit == other.limit
end

#hashObject



25
26
27
# File 'lib/nose/plans/limit.rb', line 25

def hash
  @limit
end