Class: SpreeCmCommissioner::EventChartQueries

Inherits:
Object
  • Object
show all
Defined in:
app/queries/spree_cm_commissioner/event_chart_queries.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(taxon_id:, chart_type:, refreshed: false) ⇒ EventChartQueries

chart_type: ‘participation | gender | entry_type’ taxon_id: taxon_id, refreshed: false



6
7
8
9
10
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 6

def initialize(taxon_id:, chart_type:, refreshed: false)
  @taxon_id = taxon_id
  @chart_type = chart_type || 'participation'
  @refreshed = refreshed
end

Instance Attribute Details

#chart_typeObject (readonly)

Returns the value of attribute chart_type.



3
4
5
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 3

def chart_type
  @chart_type
end

#refreshedObject (readonly)

Returns the value of attribute refreshed.



3
4
5
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 3

def refreshed
  @refreshed
end

#taxon_idObject (readonly)

Returns the value of attribute taxon_id.



3
4
5
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 3

def taxon_id
  @taxon_id
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 12

def call
  cache_key = "#{chart_type}-#{taxon_id}"
  Rails.cache.delete(cache_key) if refreshed

  product_charts = Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
    event_chart || []
  end

  SpreeCmCommissioner::EventChart.new(
    id: taxon_id,
    chart_type: chart_type,
    product_charts: product_charts
  )
end

#event_chartObject



27
28
29
30
31
32
33
34
35
# File 'app/queries/spree_cm_commissioner/event_chart_queries.rb', line 27

def event_chart
  case chart_type
  when 'participation' then participation_event_chart
  when 'entry_type' then entry_type_event_chart
  when 'guest_gender' then gender_event_chart
  when 'guest_occupation' then occupation_event_chart
  when 'guest_nationality' then nationality_event_chart
  end
end