Class: DataMapper::Paginator::ControlHelper::Elastic
- Defined in:
- lib/dm-paginator/control/elastic.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#paginator ⇒ Object
readonly
Returns the value of attribute paginator.
Instance Method Summary collapse
-
#initialize(paginator, options = {}) ⇒ Elastic
constructor
A new instance of Elastic.
- #pages(page_range = nil) ⇒ Object
Methods included from DataMapper::Paginator::ControlHelperAbstract
#normalize_page_number, #pages_in_range
Constructor Details
#initialize(paginator, options = {}) ⇒ Elastic
Returns a new instance of Elastic.
9 10 11 12 13 14 15 16 17 |
# File 'lib/dm-paginator/control/elastic.rb', line 9 def initialize paginator, = {} if !paginator.is_a?( Main ) raise ArgumentError, "paginator argument is not an instance of Main" end @paginator = paginator @options = @options[:page_range] = [:page_range].to_i || DataMapper::Paginator::default[:page_range] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/dm-paginator/control/elastic.rb', line 7 def @options end |
#paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
7 8 9 |
# File 'lib/dm-paginator/control/elastic.rb', line 7 def paginator @paginator end |
Instance Method Details
#pages(page_range = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dm-paginator/control/elastic.rb', line 19 def pages page_range = nil return unless paginator.page_count > 0 page_range = [:page_range] || page_range page_number = normalize_page_number paginator.page original_page_range = page_range page_range = page_range * 2 - 1 if original_page_range + page_number - 1 < page_range page_range = original_page_range + page_number -1 elsif original_page_range + page_number - 1 > paginator.count page_range = original_page_range + paginator.count - page_number end return super( page_range ) end |