Module: SpreeCmCommissioner::GuestDataFillStageConcern
- Extended by:
- ActiveSupport::Concern
- Included in:
- Guest
- Defined in:
- app/models/concerns/spree_cm_commissioner/guest_data_fill_stage_concern.rb
Constant Summary collapse
- STAGES =
%w[pre_registration post_registration during_check_in].freeze
Instance Method Summary collapse
- #any_fields_exist_for?(stage) ⇒ Boolean
-
#incomplete? ⇒ Boolean
Recomputes live rather than trusting the persisted data_fill_stage column, staying fully compatible with guests whose stage was set before this concern existed.
- #refresh_data_fill_stage ⇒ Object
-
#stage_completed?(stage) ⇒ Boolean
Already true when a stage has no required fields, so any_fields_exist_for? isn't needed first.
Instance Method Details
#any_fields_exist_for?(stage) ⇒ Boolean
64 65 66 |
# File 'app/models/concerns/spree_cm_commissioner/guest_data_fill_stage_concern.rb', line 64 def any_fields_exist_for?(stage) fields_for_stage(stage).exists? end |
#incomplete? ⇒ Boolean
Recomputes live rather than trusting the persisted data_fill_stage column, staying fully compatible with guests whose stage was set before this concern existed. Callers (Order, user-facing reads) sit behind caching, so the extra queries here aren't a hot-path concern.
41 42 43 |
# File 'app/models/concerns/spree_cm_commissioner/guest_data_fill_stage_concern.rb', line 41 def incomplete? STAGES.any? { |stage| !stage_completed?(stage) } end |
#refresh_data_fill_stage ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/concerns/spree_cm_commissioner/guest_data_fill_stage_concern.rb', line 25 def refresh_data_fill_stage new_stage = computed_data_fill_stage return if data_fill_stage == new_stage update_column(:data_fill_stage, new_stage) # rubocop:disable Rails/SkipsModelValidations # Guests are also refreshed one-off outside the maintenance-task/batch-job path (e.g. a # guest filling out a dynamic field via the API), so the cache clear has to live here # rather than only in the caller — otherwise has_incomplete_guest_info? could keep # returning a stale cached value after an individual guest update. line_item&.order&.clear_has_incomplete_guest_info_cache end |
#stage_completed?(stage) ⇒ Boolean
Already true when a stage has no required fields, so any_fields_exist_for? isn't needed first. Uses pluck/exists?, not any?/map, so it always queries fresh instead of reusing an association target cached from an earlier call.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/models/concerns/spree_cm_commissioner/guest_data_fill_stage_concern.rb', line 48 def stage_completed?(stage) # Pre-registration is considered complete if the order is completed return true if stage.to_s == 'pre_registration' && line_item&.order&.completed? == true # Once the line item's own duration has ended, pre/post-registration info is moot — don't # keep asking for it. during_check_in is deliberately excluded: staff may still log # check-in-stage data after the event occurs. return true if %w[pre_registration post_registration].include?(stage.to_s) && line_item&.ended? == true required_field_ids = fields_for_stage(stage).pluck(:id) return true if required_field_ids.empty? filled_field_ids = guest_dynamic_fields.pluck(:dynamic_field_id) required_field_ids.to_set.subset?(filled_field_ids.to_set) end |