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.



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

def initialize(relation, model)
  @relation = relation
  @model = Model.new(model, relation)
end

Instance Attribute Details

#modelObject (readonly)

the current model & the scope



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

def model
  @model
end

#relationObject (readonly)

the current model & the scope



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

def relation
  @relation
end

Instance Method Details

#afterObject



21
22
23
24
# File 'lib/nexter/wrap.rb', line 21

def after
  query = Query.new(model.values, :next)
  relation.where( query.wheres.join(' OR ') )
end

#beforeObject



26
27
28
29
30
# File 'lib/nexter/wrap.rb', line 26

def before
  query = Query.new(model.values, :previous)
  relation.where( query.wheres.join(' OR ') ).
          reorder( query.reorders.join(", ") )
end

#nextObject

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



13
14
15
# File 'lib/nexter/wrap.rb', line 13

def next
  @next||=after.first
end

#previousObject



17
18
19
# File 'lib/nexter/wrap.rb', line 17

def previous
  @prev||=before.first
end