Class: Nexter::Wrap

Inherits:
Object
  • Object
show all
Defined in:
lib/nexter/wrap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, model) ⇒ Wrap

Returns a new instance of Wrap.



14
15
16
17
18
19
20
21
# File 'lib/nexter/wrap.rb', line 14

def initialize(relation, model)
  @relation = relation
  @model = model
  @order_values = parse_order( relation.order_values )
  @associations = relation.includes_values
  # @cursor_column = extract_attr( @ranges.pop )
  # @cursor = model.send( @cursor_column.to_sym, )
end

Instance Attribute Details

#associationsObject (readonly)

extracted values from the relation



8
9
10
# File 'lib/nexter/wrap.rb', line 8

def associations
  @associations
end

#modelObject (readonly)

the current model & the scope



5
6
7
# File 'lib/nexter/wrap.rb', line 5

def model
  @model
end

#order_valuesObject (readonly)

extracted values from the relation



8
9
10
# File 'lib/nexter/wrap.rb', line 8

def order_values
  @order_values
end

#relationObject (readonly)

the current model & the scope



5
6
7
# File 'lib/nexter/wrap.rb', line 5

def relation
  @relation
end

#reordersObject (readonly)

list of build strings for finale SQL



11
12
13
# File 'lib/nexter/wrap.rb', line 11

def reorders
  @reorders
end

#wheresObject (readonly)

list of build strings for finale SQL



11
12
13
# File 'lib/nexter/wrap.rb', line 11

def wheres
  @wheres
end

Instance Method Details

#afterObject



33
34
35
36
37
38
# File 'lib/nexter/wrap.rb', line 33

def after
  derange = cut(:next)
  r = relation.where( wheres.join(' OR ') )
  # r = r.order(:id) if derange.reorder
  r
end

#beforeObject



40
41
42
43
# File 'lib/nexter/wrap.rb', line 40

def before
  cut(:previous)
  relation.where( wheres.join(' OR ') ).reorder( reorders.join(", ") )
end

#nextObject

TODO : let user determine which strategy to choose: e.g: carousel or stay there



25
26
27
# File 'lib/nexter/wrap.rb', line 25

def next
  after.first
end

#previousObject



29
30
31
# File 'lib/nexter/wrap.rb', line 29

def previous
  before.first
end