mardi 30 août 2016

update hash value with another hash

I wish my hash @fulfilments_to_send_notifications looked like:

{
  some_status: values: {
                     order_fulfillments: #some orders,
                     role: 'role',
                     minutes_between: 15 #some int
  }
}

I'm trying to update the values, currently it's just order fulfillments, but my code doesn't update it. I don't have the role or the minutes_between in my hash. How do I update it?

  def collect_fulfillments(late_fulfillments, role, status, minutes_between)
    @fulfilments_to_send_notifications[status] = {
      order_fulfillments: late_fulfillments,
      role: role,
      minutes_between: minutes_between
    }
  end

  def current_fulfillments
    @fulfilments_to_send_notifications ||= {}
    return unless current_fulfillments ||= begin
      OrderFulfillment.includes(:timestamps).new_fulfillments(10.days.ago)
    end # <---------- it works, returns some orders

    current_fulfillments.group_by(&:shopper_status).select do 
      |status, order_fulfillments|

      if status == 'shopper_started'
        if late_fulfillments =
          order_fulfillments.select do |order_fulfillment|
            order_fulfillment.pending_shopper_checkout?
          end
          collect_fulfillments( # <----- doesn't update the values
            late_fulfillments,
            :shopper,
            status,
            TIME_BETWEEN_NOTIFICATIONS_IN_MINUTES
          )
        end
      end
    @fulfilments_to_send_notifications
  end
end

Aucun commentaire:

Enregistrer un commentaire