Class: A2::Paginated
- Defined in:
- lib/a2/mixins/paginated.rb
Direct Known Subclasses
Subcommand::Infra::ListAllCheckedInNodes, Subcommand::Infra::ListNodeRuns, Subcommand::NodeMgmt::BulkDeleteByFilter, Subcommand::NodeMgmt::Search, Subcommand::Reporting::ExportNodeReports, Subcommand::Reporting::ListReports
Instance Attribute Summary
Attributes inherited from Filtered
Instance Method Summary collapse
- #generate_paginated_query_string ⇒ Object
-
#initialize(name, opts = {}) ⇒ Paginated
constructor
A new instance of Paginated.
- #with_paginated_filter_json {|json| ... } ⇒ Object
- #with_paginated_filter_query {|query_string| ... } ⇒ Object
Methods inherited from Filtered
#generate_json_filters, #generate_query_filters, #parse_filters, #set_custom_opts!, #set_filter_optparse_options!, #with_filter_query
Constructor Details
#initialize(name, opts = {}) ⇒ Paginated
Returns a new instance of Paginated.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/a2/mixins/paginated.rb', line 3 def initialize(name, opts = {}) disable_sort_opts = opts.delete(:disable_sort_opts) || false super(name, opts) @opt[:order] = 'ASC' unless disable_sort_opts .on('-o', '--order ORDER', 'Return the results in ascending or descending order. Default is "ASC".') do |order| @opt[:order] = order end unless disable_sort_opts .on('-s', '--sort SORT', 'Sort the results on a specific field.') do |sort| @opt[:sort] = sort end unless disable_sort_opts .on('-p', '--page PAGE', Integer, 'Starting page for the results. Default is 0') do |page| @opt[:page] = page end .on('-P', '--per-page PER_PAGE', Integer, 'The number of results on each page. Default is 100') do |per_page| @opt[:per_page] = per_page end (, @query_filter) end |
Instance Method Details
#generate_paginated_query_string ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/a2/mixins/paginated.rb', line 27 def generate_paginated_query_string query = generate_query_filters query << "&pagination.page=#{@opt[:page]}" if @opt[:page] query << "&pagination.page=#{@opt[:per_page]}" if @opt[:per_page] query << "&sorting.field=#{@opt[:sort]}" if @opt[:sort] query << "&sorting.order=#{@opt[:order]}" if @opt[:order] query end |
#with_paginated_filter_json {|json| ... } ⇒ Object
22 23 24 25 |
# File 'lib/a2/mixins/paginated.rb', line 22 def with_paginated_filter_json(&block) json = generate_json_filters yield(json) end |
#with_paginated_filter_query {|query_string| ... } ⇒ Object
36 37 38 39 |
# File 'lib/a2/mixins/paginated.rb', line 36 def with_paginated_filter_query(&block) query_string = generate_paginated_query_string yield(query_string) end |