Class: Workarea::AdminRedemptionsExport
- Inherits:
-
Object
- Object
- Workarea::AdminRedemptionsExport
- Includes:
- GlobalID::Identification, Search::Pagination
- Defined in:
- app/queries/workarea/admin_redemptions_export.rb
Instance Attribute Summary collapse
-
#gift_cards_query_id ⇒ Object
(also: #id)
readonly
Returns the value of attribute gift_cards_query_id.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ AdminRedemptionsExport
constructor
A new instance of AdminRedemptionsExport.
- #results ⇒ Object
-
#scroll(options = {}, &block) ⇒ Object
to match Search::Query method arguments.
- #total ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ AdminRedemptionsExport
17 18 19 20 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 17 def initialize(params = {}) @params = params.with_indifferent_access @gift_cards_query_id = params[:gift_cards_query_id] end |
Instance Attribute Details
#gift_cards_query_id ⇒ Object (readonly) Also known as: id
Returns the value of attribute gift_cards_query_id.
10 11 12 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 10 def gift_cards_query_id @gift_cards_query_id end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 10 def params @params end |
Class Method Details
.find(id) ⇒ Object
13 14 15 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 13 def self.find(id) new(gift_cards_query_id: id) end |
Instance Method Details
#results ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 22 def results @results ||= PagedArray.new( redemptions_for(gift_card_ids).to_a, page, per_page, gift_cards_query.total # ensure correct paginating ) end |
#scroll(options = {}, &block) ⇒ Object
to match Search::Query method arguments
31 32 33 34 35 36 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 31 def scroll( = {}, &block) # to match Search::Query method arguments results.total_pages.times do |page| query = self.class.new(params.merge(page: page + 1)) yield query.results end end |
#total ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/queries/workarea/admin_redemptions_export.rb', line 38 def total @total ||= begin result = 0 gift_cards_query.results.total_pages.times do |page| page_params = gift_cards_query.params.merge(page: page + 1) page_query = gift_cards_query.class.new(page_params) page_query.define_singleton_method(:per_page) { Workarea.config.bulk_action_per_page } result += redemptions_for(page_query.results.map(&:id)).count end result end end |