Class: Ludy::Page
- Inherits:
-
Object
- Object
- Ludy::Page
- Defined in:
- lib/ludy/paginator.rb
Overview
which was produced by Paginator#page / Paginator#[], representing page that contained target data. it would use lazy fetching, whenever you need the data, the fetcher would be invoked that time. whenever the data was fetched, it won’t fetch again. it you need refetch, call Page#fetch
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
pager to get the original pager; page to get the number of this page.
-
#pager ⇒ Object
readonly
pager to get the original pager; page to get the number of this page.
Instance Method Summary collapse
-
#==(rhs) ⇒ Object
if the page numbers and the pagers are equal, then the pages are equal.
-
#begin ⇒ Object
the real beginning index.
-
#data ⇒ Object
get the data fetched from pager.
-
#end ⇒ Object
the real ending index (need fetch, because we don’t know the size).
-
#fetch ⇒ Object
explicitly fetch the data from pager.
-
#initialize(pager, page) ⇒ Page
constructor
don’t create a page instance yourself unless you have to.
-
#method_missing(msg, *args, &block) ⇒ Object
any other method call would delegate to the data, e.g., each, to_a, map, first, method_you_defined, etc.
-
#next ⇒ Object
return the page instance next to this page.
-
#prev ⇒ Object
return the page instance prev to this page.
Constructor Details
#initialize(pager, page) ⇒ Page
don’t create a page instance yourself unless you have to
17 |
# File 'lib/ludy/paginator.rb', line 17 def initialize pager, page; @pager, @page = pager, page; end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(msg, *args, &block) ⇒ Object
any other method call would delegate to the data, e.g., each, to_a, map, first, method_you_defined, etc.
38 39 40 |
# File 'lib/ludy/paginator.rb', line 38 def method_missing msg, *args, &block self.data.public_send msg, *args, &block end |
Instance Attribute Details
#page ⇒ Object (readonly)
pager to get the original pager; page to get the number of this page
15 16 17 |
# File 'lib/ludy/paginator.rb', line 15 def page @page end |
#pager ⇒ Object (readonly)
pager to get the original pager; page to get the number of this page
15 16 17 |
# File 'lib/ludy/paginator.rb', line 15 def pager @pager end |
Instance Method Details
#==(rhs) ⇒ Object
if the page numbers and the pagers are equal, then the pages are equal.
24 25 26 27 |
# File 'lib/ludy/paginator.rb', line 24 def == rhs @page == rhs.instance_variable_get('@page' ) and @pager == rhs.instance_variable_get('@pager') end |
#begin ⇒ Object
the real beginning index
33 |
# File 'lib/ludy/paginator.rb', line 33 def begin; @pager.offset @page; end |
#data ⇒ Object
get the data fetched from pager
31 |
# File 'lib/ludy/paginator.rb', line 31 def data; @data ||= fetch; end |
#end ⇒ Object
the real ending index (need fetch, because we don’t know the size)
35 |
# File 'lib/ludy/paginator.rb', line 35 def end; self.begin + self.size - 1; end |
#fetch ⇒ Object
explicitly fetch the data from pager
29 |
# File 'lib/ludy/paginator.rb', line 29 def fetch; @data = @pager.fetcher[self.begin, @pager.per_page]; end |
#next ⇒ Object
return the page instance next to this page
19 |
# File 'lib/ludy/paginator.rb', line 19 def next; @pager.page(@page+1); end |
#prev ⇒ Object
return the page instance prev to this page
21 |
# File 'lib/ludy/paginator.rb', line 21 def prev; @pager.page(@page-1); end |