You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
moduleFeedsclassProperty@@attribute_names=[:name,:latitude,:longitude,:street,:city,:state,:floorplan,]attr_accessor *@@attribute_names# https://stackoverflow.com/questions/12763016/how-to-cleanly-initialize-attributes-in-ruby-with-newdefinitialize(params={})@@attribute_names.eachdo |attr|
instance_variable_set("@#{attr}",params[attr])ifparams[attr]endend# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.defattributesHash[@@attribute_names.map{ |name| [name,self.send(name)]}]endendend
classContactFormincludeActiveModel::ModelATTRIBUTE_NAMES=%i[namephoneemailmessagesubscribe].freezeattr_accessor(*ATTRIBUTE_NAMES)validates:name,presence: true,length: {maximum: 50}validates:email,length: {maximum: 255},format: {with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i}# Error messages are available after valid? is calleddefsubmitifvalid?trueelsefalseendend# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.defattributesHash[ATTRIBUTE_NAMES.map{ |name| [name,send(name)]}]endend
moduleInventorymoduleSomeApiclassShippingInfoSerializerattr_reader:customer,:designdefinitialize(customer_or_id)@customer=self.class.find_customer(customer_or_id)@design=self.class.find_customer_design(@customer)raise(ArgumentError,"shipment data is blank")if@customer.shipment&.data.blank?enddefas_json(*)shipping_info=ShippingInfo.new(productSourcingOrderId: product_sourcing_order_id,items: items)shipping_info.validate!shipping_info.attributesenddefproduct_sourcing_order_idcustomer.warehouse_customer_detail.warehouse_order_idenddefitemsdata=customer.shipment.datadeliver_by=customer.shipment.deliver_bynormalized_package_items.mapdo |package_item|
# sometimes only SKU is providedproduct_id,sku=package_item.values_at("product_id","sku")product_id ||= Inventory::ItemDesign.product_id_from_sku(sku)shipment_details=ShippingInfoItemShipmentDetails.newshipment_details.trackingNumber=package_item["tracking_number"] || data["tracking_number"]shipment_details.shippingServiceProvider=data["carrier"]shipment_details.shippingDate=package_item["shipped_at"] || data["shipped_at"] || customer.shipment.shipped_atshipment_details.estimatedDeliveryDate=deliver_byshipment_details.validate!item=ShippingInfoItem.newitem.productId=Inventory::ItemDesign.composed_product_id(design,product_id: product_id)item.shipmentDetails=shipment_details.attributesitem.validate!itemendenddefnormalized_package_itemspackages=customer.shipment.data["packages"].presenceifpackages&.dig(0,"package_items").blank?# make pseudo-package-items based on piecescustomer.pieces.mapdo |piece|
{"sku"=>piece.product_sku}endelse# flatten the nested structurepackages.flat_mapdo |package|
base_item=package.slice("tracking_number","shipped_at")package.fetch("package_items").map{ |package_item| base_item.merge(package_item)}endendendclass << selfdeffind_customer(customer)Customer.joins(:shipment,:warehouse_customer_detail).includes(fulfillment: {orders: :products}).find(customer.to_param)rescueActiveRecord::RecordNotFoundraiseArgumentError,"customer does not have warehouse customer detail or shipment association"enddeffind_customer_design(customer)customer&.fulfillment&.design || raise(ArgumentError,"customer does not have design")endendclassModelincludeActiveModel::ModelincludeActiveModel::Validations::Callbacksdefattributesas_json(except: ["validation_context","errors"])endendclassShippingInfo < Modelattr_accessor:productSourcingOrderId,:itemsbefore_validation->{self.productSourcingOrderId=productSourcingOrderId.to_s}validates:productSourcingOrderId,presence: truevalidates:items,presence: trueendclassShippingInfoItem < Modelattr_accessor:productId,:shipmentDetailsbefore_validation->{self.productId=productId.to_s}validates:productId,presence: truevalidates:shipmentDetails,presence: trueendclassShippingInfoItemShipmentDetails < Modelattr_accessor:trackingNumber,:shippingServiceProvider,:shippingDate,:estimatedDeliveryDatebefore_validation:format_timestampsvalidates:trackingNumber,presence: truevalidates:shippingServiceProvider,presence: true,inclusion: {in: %w[UPSFedExUSPSDHL]}validates:shippingDate,presence: truevalidates:estimatedDeliveryDate,presence: trueprivatedefformat_timestampsself.shippingDate=shippingDate.to_time.iso8601ifshippingDate.present?self.estimatedDeliveryDate=estimatedDeliveryDate.to_time.iso8601ifestimatedDeliveryDate.present?endendendendend
Rails 5.0