Class: Golden::QueryResultPresenter
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize
Instance Attribute Details
#presenter_class ⇒ Object
Returns the value of attribute presenter_class.
24
25
26
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 24
def presenter_class
@presenter_class
end
|
#records ⇒ Object
Returns the value of attribute records.
24
25
26
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 24
def records
@records
end
|
Class Method Details
.collect(result, presenter_class) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 6
def collect(result, presenter_class)
new(
records: paginated_array(result),
presenter_class: presenter_class.to_s
)
end
|
.paginated_array(result) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 13
def paginated_array(result)
return result unless result.is_a?(Array)
return result unless ::Object.const_defined? 'Kaminari'
return Kaminari.paginate_array([], total_count: 0).page(1) if result.empty?
Kaminari.paginate_array(result).page(1).per(result.size)
end
|
Instance Method Details
#current_page ⇒ Object
42
43
44
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 42
def current_page
records.current_page
end
|
#each(&block) ⇒ Object
26
27
28
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 26
def each(&block)
presenters.each(&block)
end
|
#first_page? ⇒ Boolean
58
59
60
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 58
def first_page?
records.first_page?
end
|
#last_page? ⇒ Boolean
62
63
64
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 62
def last_page?
records.last_page?
end
|
#next_page ⇒ Object
50
51
52
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 50
def next_page
records.next_page
end
|
#out_of_range? ⇒ Boolean
66
67
68
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 66
def out_of_range?
records.out_of_range?
end
|
#per_page ⇒ Object
46
47
48
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 46
def per_page
records.limit_value
end
|
#presenters ⇒ Object
30
31
32
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 30
def presenters
@presenters ||= records.map { |record| presenter_class.constantize.new record }
end
|
#prev_page ⇒ Object
54
55
56
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 54
def prev_page
records.prev_page
end
|
#total_count ⇒ Object
34
35
36
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 34
def total_count
records.total_count
end
|
#total_pages ⇒ Object
38
39
40
|
# File 'lib/golden/objects/query/query_result_presenter.rb', line 38
def total_pages
records.total_pages
end
|