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
# An abstract class that implement common logic for generating data for summary charts and table.classPropertyEventclassSummarymoduleModelsclassBaseincludeActiveModel::ModelincludeActiveModel::AttributeAssignmentdef [](key)send(key)endendclassChartSlice < Baseattr_accessor(:color,:label,:value)endclassTableRow < Baseattr_accessor(:name,:event_count,:event_percentage,:lead_count,:lead_percentage,:lead_contribution_count,:lead_contribution_details)definitialize(*)superassign_default_valuesendprivatedefassign_default_valuesself.name ||= ""self.event_count ||= 0self.event_percentage ||= 0self.lead_count ||= 0self.lead_percentage ||= 0self.lead_contribution_count ||= 0self.lead_contribution_details ||= 0endendendendend
moduleSomeContextclassRefundsController < ::ApplicationControllerbefore_action:login_requiredbefore_action:find_orderbefore_action:find_problemdefnew@refund=Refund.newenddefcreate@refund=Refund.new(refund_params)if@refund.saveflash[:success]="Refund created successfully."redirect_toorder_problem_url(@order,@problem)elserender:newendendprivatedeffind_order@order=Order.find(params.fetch(:order_id))enddeffind_problem@problem=@order.problem.find(params.fetch(:problem_id))enddefrefund_paramsparams.require(:refund).permit(:amount)endendclassRefundincludeActiveModel::Modelattr_accessor:amountvalidates:amount,numericality: {greater_than: 0}defsaveifvalid?# TODO: process refundelsefalseendendendend
# This class will contain all required logic to properly "present" the data needed for Rockwell (BladeRunner) to
# perform the required work. This means loading information such as the correct design blueprint,
# order information (strategy - digital flag) and other endpoint data into a single structured response.
class ArtPresenter < ::Dry::Struct
attribute :order_details_id, ::Types::Coercible::Integer.optional
attribute :design_id, ::Types::Coercible::Integer.optional
attribute :palette, ::Types::Strict::String.optional
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
Simple Active Model