Module: LinkedRails::Collection::Infinite

Extended by:
ActiveSupport::Concern
Included in:
InfiniteView
Defined in:
app/models/linked_rails/collection/infinite.rb

Instance Method Summary collapse

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'app/models/linked_rails/collection/infinite.rb', line 12

def any?
  return members_query.any? if members_query.is_a?(ActiveRecord::Relation)

  count.positive?
end

#initialize(orignial = {}) ⇒ Object



18
19
20
21
22
# File 'app/models/linked_rails/collection/infinite.rb', line 18

def initialize(orignial = {})
  attrs = orignial.with_indifferent_access
  attrs[:before] = attrs[:before]&.map { |val| val.with_indifferent_access }
  super(attrs)
end

#nextObject



24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/linked_rails/collection/infinite.rb', line 24

def next
  return if before.blank? || members.blank?

  current_opts = {
    collection: collection,
    filter: filter
  }
  next_view = collection.view_with_opts(current_opts.merge(before: next_before_values))

  next_view.iri if next_view.any?
end

#prevObject



36
# File 'app/models/linked_rails/collection/infinite.rb', line 36

def prev; end

#typeObject



38
39
40
# File 'app/models/linked_rails/collection/infinite.rb', line 38

def type
  :infinite
end