Class: RestaurantCpt::Cell::CustomerRootPage

Inherits:
Object
  • Object
show all
Defined in:
app/concepts/restaurant_cpt/cell/customer_root_page.rb

Overview

Used by customer root path controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CustomerRootPage

Returns a new instance of CustomerRootPage.



10
11
12
13
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 10

def initialize(options = {})
  self.default_page = options.fetch(:page, 2)
  self.per_page = options.fetch(:per_page, 15)
end

Instance Attribute Details

#default_pageObject

Returns the value of attribute default_page.



7
8
9
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 7

def default_page
  @default_page
end

#per_pageObject

Returns the value of attribute per_page.



7
8
9
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 7

def per_page
  @per_page
end

Instance Method Details

#collectionObject



24
25
26
27
28
29
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 24

def collection
  @collection ||= Restaurant.includes(:translations)
                            .active
                            .not_expired
                            .order('rank ASC')
end

#initial_dataObject



15
16
17
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 15

def initial_data
  render collection.page(1).per(per_page)
end

#next_restaurants(page: nil) ⇒ Object



19
20
21
22
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 19

def next_restaurants(page: nil)
  pp = page || default_page
  render(collection.page(pp).per(per_page))
end

#render(resources) ⇒ Object



31
32
33
34
# File 'app/concepts/restaurant_cpt/cell/customer_root_page.rb', line 31

def render(resources)
  ActiveModelSerializers::SerializableResource.new resources,
                                                   each_serializer: Websites::RestaurantSliderSerializer
end