Module: ActiveRecord::Cursor::ModelExtension::ClassMethods
- Defined in:
- lib/activerecord/cursor/model_extension.rb
Instance Method Summary collapse
- #cursor(options = {}) ⇒ Object
- #in_order ⇒ Object
- #next_cursor ⇒ Object
- #on_cursor ⇒ Object
- #prev_cursor ⇒ Object
Instance Method Details
#cursor(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/activerecord/cursor/model_extension.rb', line 9 def cursor( = {}) @options = .merge!().symbolize_keys! @options[:direction] = if @options.key?(:start) || @options.key?(:stop) @options.key?(:start) ? :start : :stop end @cursor = Params.decode(@options[@options[:direction]]).value @records = on_cursor.in_order.limit(@options[:size] + 1) set_cursor @records rescue ActiveRecord::StatementInvalid raise Cursor::InvalidCursor end |
#in_order ⇒ Object
44 45 46 |
# File 'lib/activerecord/cursor/model_extension.rb', line 44 def in_order order("#{column} #{by}", "#{table_name}.id #{by}") end |
#next_cursor ⇒ Object
23 24 25 |
# File 'lib/activerecord/cursor/model_extension.rb', line 23 def next_cursor @next end |
#on_cursor ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/activerecord/cursor/model_extension.rb', line 31 def on_cursor if @cursor.nil? where(nil) else where( "(#{column} = ? AND #{table_name}.id #{sign_of_inequality} ?) OR (#{column} #{sign_of_inequality} ?)", @cursor[:key], @cursor[:id], @cursor[:key] ) end end |
#prev_cursor ⇒ Object
27 28 29 |
# File 'lib/activerecord/cursor/model_extension.rb', line 27 def prev_cursor @prev end |