Class: Munificent::KeyAssignment::KeyAssigner
- Inherits:
-
Object
- Object
- Munificent::KeyAssignment::KeyAssigner
- Defined in:
- app/services/munificent/key_assignment/key_assigner.rb
Instance Method Summary collapse
-
#assign(donator_bundle_tier, fundraiser: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
-
#initialize(key_manager: nil) ⇒ KeyAssigner
constructor
A new instance of KeyAssigner.
Constructor Details
#initialize(key_manager: nil) ⇒ KeyAssigner
Returns a new instance of KeyAssigner.
4 5 6 |
# File 'app/services/munificent/key_assignment/key_assigner.rb', line 4 def initialize(key_manager: nil) @key_manager = key_manager || KeyManager.new end |
Instance Method Details
#assign(donator_bundle_tier, fundraiser: nil) ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/services/munificent/key_assignment/key_assigner.rb', line 8 def assign(donator_bundle_tier, fundraiser: nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity return if donator_bundle_tier.nil? return if donator_bundle_tier.locked? fundraiser ||= donator_bundle_tier.bundle_tier.fundraiser donator_bundle_tier.bundle_tier.games.each do |game| next if @key_manager.key_assigned?(game, donator_bundle_tier:) @key_manager.lock_unassigned_key(game, fundraiser:) do |key| donator = donator_bundle_tier.donator_bundle.donator if key key.update!(donator_bundle_tier:) if defined?(NotificationsMailer) && donator.email_address.present? && donator.confirmed? NotificationsMailer.bundle_assigned(donator).deliver_now end elsif defined?(PanicMailer) PanicMailer.missing_key(donator, game).deliver_now end end end end |