Class: Nexter::Wrap
- Inherits:
-
Object
- Object
- Nexter::Wrap
- Defined in:
- lib/nexter/wrap.rb
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
extracted values from the relation.
-
#model ⇒ Object
readonly
the current model & the scope.
-
#order_values ⇒ Object
readonly
extracted values from the relation.
-
#relation ⇒ Object
readonly
the current model & the scope.
-
#reorders ⇒ Object
readonly
list of build strings for finale SQL.
-
#wheres ⇒ Object
readonly
list of build strings for finale SQL.
Instance Method Summary collapse
- #after ⇒ Object
- #before ⇒ Object
-
#initialize(relation, model) ⇒ Wrap
constructor
A new instance of Wrap.
-
#next ⇒ Object
TODO : let user determine which strategy to choose: e.g: carousel or stay there.
- #previous ⇒ Object
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
#associations ⇒ Object (readonly)
extracted values from the relation
8 9 10 |
# File 'lib/nexter/wrap.rb', line 8 def associations @associations end |
#model ⇒ Object (readonly)
the current model & the scope
5 6 7 |
# File 'lib/nexter/wrap.rb', line 5 def model @model end |
#order_values ⇒ Object (readonly)
extracted values from the relation
8 9 10 |
# File 'lib/nexter/wrap.rb', line 8 def order_values @order_values end |
#relation ⇒ Object (readonly)
the current model & the scope
5 6 7 |
# File 'lib/nexter/wrap.rb', line 5 def relation @relation end |
#reorders ⇒ Object (readonly)
list of build strings for finale SQL
11 12 13 |
# File 'lib/nexter/wrap.rb', line 11 def reorders @reorders end |
#wheres ⇒ Object (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
#after ⇒ Object
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 |
#before ⇒ Object
40 41 42 43 |
# File 'lib/nexter/wrap.rb', line 40 def before cut(:previous) relation.where( wheres.join(' OR ') ).reorder( reorders.join(", ") ) end |
#next ⇒ Object
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 |
#previous ⇒ Object
29 30 31 |
# File 'lib/nexter/wrap.rb', line 29 def previous before.first end |