Class: Ardb::RelationSpy

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/relation_spy.rb

Defined Under Namespace

Classes: AppliedExpression

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRelationSpy

Returns a new instance of RelationSpy.



10
11
12
13
14
15
# File 'lib/ardb/relation_spy.rb', line 10

def initialize
  @applied, @results = [], []
  @order_values = []
  @reverse_order_value = nil
  @offset_value, @limit_value = nil, nil
end

Instance Attribute Details

#appliedObject (readonly)

Returns the value of attribute applied.



5
6
7
# File 'lib/ardb/relation_spy.rb', line 5

def applied
  @applied
end

#limit_valueObject

Returns the value of attribute limit_value.



7
8
9
# File 'lib/ardb/relation_spy.rb', line 7

def limit_value
  @limit_value
end

#offset_valueObject

Returns the value of attribute offset_value.



7
8
9
# File 'lib/ardb/relation_spy.rb', line 7

def offset_value
  @offset_value
end

#order_valuesObject

Returns the value of attribute order_values.



6
7
8
# File 'lib/ardb/relation_spy.rb', line 6

def order_values
  @order_values
end

#resultsObject

Returns the value of attribute results.



8
9
10
# File 'lib/ardb/relation_spy.rb', line 8

def results
  @results
end

#reverse_order_valueObject

Returns the value of attribute reverse_order_value.



6
7
8
# File 'lib/ardb/relation_spy.rb', line 6

def reverse_order_value
  @reverse_order_value
end

Instance Method Details

#==(other) ⇒ Object



57
58
59
# File 'lib/ardb/relation_spy.rb', line 57

def ==(other)
  @applied == other.applied
end

#allObject



49
50
51
# File 'lib/ardb/relation_spy.rb', line 49

def all
  @results[(@offset_value || 0), (@limit_value || @results.size)] || []
end

#countObject



53
54
55
# File 'lib/ardb/relation_spy.rb', line 53

def count
  all.size
end

#limit(value) ⇒ Object



37
38
39
40
41
# File 'lib/ardb/relation_spy.rb', line 37

def limit(value)
  @limit_value = value ? value.to_i : nil
  @applied << AppliedExpression.new(:limit, [ value ])
  self
end

#offset(value) ⇒ Object



43
44
45
46
47
# File 'lib/ardb/relation_spy.rb', line 43

def offset(value)
  @offset_value = value ? value.to_i : 0
  @applied << AppliedExpression.new(:offset, [ value ])
  self
end

#order(*args) ⇒ Object



31
32
33
34
35
# File 'lib/ardb/relation_spy.rb', line 31

def order(*args)
  @order_values += args
  @applied << AppliedExpression.new(:order, args)
  self
end