Sha256: 38fc844fef2ade7151cfdf01f85252def64463c442979b127ccc2e3332f6afad
Contents?: true
Size: 791 Bytes
Versions: 3
Compression:
Stored size: 791 Bytes
Contents
class StripeModelCallbacks::AttributesAssignerService < ServicePattern::Service attr_reader :attributes, :model, :stripe_model def initialize(attributes:, model:, stripe_model:) @attributes = attributes @model = model @stripe_model = stripe_model end def execute attributes.each do |attribute| next unless stripe_model.respond_to?(attribute) value = stripe_model.__send__(attribute) if attribute == "metadata" value = JSON.generate(value) elsif attribute == "created" && value value = Time.zone.at(value) end model.__send__(setter_method(attribute), value) end succeed! end def setter_method(attribute) if attribute == "id" "stripe_id=" else "#{attribute}=" end end end
Version data entries
3 entries across 3 versions & 1 rubygems