Module: Facet::Core
Instance Method Summary collapse
- #filter_for(filter_by, all) ⇒ Object private
- #filtered? ⇒ Boolean
- #initialize(current_page: nil, filter_by: nil, sort_by: nil, all: false, paginate: true, source: nil) ⇒ Object
- #page_for(current_page, paginate) ⇒ Object private
- #paginated? ⇒ Boolean
- #sort_for(sort_by) ⇒ Object private
- #sorted? ⇒ Boolean
- #source? ⇒ Boolean
Instance Method Details
#filter_for(filter_by, all) ⇒ Object (private)
43 44 45 |
# File 'lib/facet/concerns/core.rb', line 43 def filter_for(filter_by, all) filter_by.presence || ((default_filter? && !all) ? default_filter : nil) end |
#filtered? ⇒ Boolean
23 24 25 |
# File 'lib/facet/concerns/core.rb', line 23 def filtered? filter_by.present? end |
#initialize(current_page: nil, filter_by: nil, sort_by: nil, all: false, paginate: true, source: nil) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/facet/concerns/core.rb', line 12 def initialize(current_page: nil, filter_by: nil, sort_by: nil, all: false, paginate: true, source: nil) @current_page = page_for(current_page, paginate) @filter_by = filter_for(filter_by, all) @sort_by = sort_for(sort_by) @source = source end |
#page_for(current_page, paginate) ⇒ Object (private)
37 38 39 40 41 |
# File 'lib/facet/concerns/core.rb', line 37 def page_for(current_page, paginate) return current_page.presence || default_page if paginate && pagination? raise ArgumentError, "pagination is disabled for this facet." if current_page.present? end |
#paginated? ⇒ Boolean
19 20 21 |
# File 'lib/facet/concerns/core.rb', line 19 def paginated? current_page.present? end |
#sort_for(sort_by) ⇒ Object (private)
47 48 49 |
# File 'lib/facet/concerns/core.rb', line 47 def sort_for(sort_by) sort_by.presence || (default_sort? ? default_sort : nil) end |
#sorted? ⇒ Boolean
27 28 29 |
# File 'lib/facet/concerns/core.rb', line 27 def sorted? sort_by.present? end |
#source? ⇒ Boolean
31 32 33 |
# File 'lib/facet/concerns/core.rb', line 31 def source? source.present? end |