Class: HhPackage::PackageAttrGenerator
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- HhPackage::PackageAttrGenerator
- Defined in:
- app/workers/hh_package/package_attr_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Class Method Details
.generate_attributes(package) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/workers/hh_package/package_attr_generator.rb', line 26 def self.generate_attributes(package) min_seat = package.dynamic_pricings.map do |pricing| pricing.decide_min_seat get_min_seat_for_per_pack: true end.min max_seat = package.dynamic_pricings.map do |pricing| pricing.decide_max_seat get_possible_max_seat_for_per_pack: true end.max = if package.instance_of?(HhPackage::Package::HungryAtHome) quantity_limit = package..map(&:quantity_limit).compact.sum.to_i quantity_limit > 0 ? quantity_limit : 1 else 100_000 end reservation_duration = package.reservation_duration { min_seat: min_seat, max_seat: max_seat, reservation_duration: reservation_duration, menu_quantity_limit: } end |
Instance Method Details
#perform(opts) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/workers/hh_package/package_attr_generator.rb', line 4 def perform(opts) opts = opts.with_indifferent_access package_id = opts.delete :package_id package_type = opts.delete :package_type old_package_id = opts.delete :old_package_id package = package_type.constantize.find_by id: package_id return if package.blank? old_package = old_package_id.present? ? package_type.constantize.find_by(id: old_package_id) : nil package_attr = package.fetch_package_attr.presence || package.build_package_attr attributes = self.class.generate_attributes(package) if old_package.present? attributes = attributes.merge({ custom_net_price: old_package.fetch_package_attr.custom_net_price, original_price_cents: old_package.fetch_package_attr.original_price_cents }) end package_attr.assign_attributes attributes package_attr.save! end |