Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related to object changes: incompatible with CarrierWave::Uploader::Base #1483

Open
gtv-thiennguyen opened this issue Jul 15, 2024 · 0 comments

Comments

@gtv-thiennguyen
Copy link

gtv-thiennguyen commented Jul 15, 2024

Thank you for your contribution!

Due to limited volunteers, issues that do not follow this template will be
closed without comment.

Is your feature suggestion related to a problem? Please describe.

  • Currently, if the models use CarrierWave to save files they will lead to error while trying to save CarrierWave::Uploader::Base objects as changes

A clear and concise description of the problem. You may find the
bug report template
helpful.

Describe the solution you'd like to build

  • My solution: I would like to adjust the method serialize_object_changes of Events::Base

A clear and concise description of what you want to build.

Describe alternatives you've considered
Currently, it's like below

module Events
  class Base
    private
    def serialize_object_changes(changes)
      AttributeSerializers::ObjectChangesAttribute.
        new(@record.class).
        serialize(changes)

      # We'd like to convert this `HashWithIndifferentAccess` to a plain
      # `Hash`, but we don't, to save memory.
      changes
    end
  end
end

I would like to change:

module Events
  class Base
    private
    def serialize_object_changes(changes)
      changes = changes.transform_values do |values|
        values.map do |value|
          if value.is_a?(CarrierWave::Uploader::Base)
            value.url
          else
            value
          end
        end
      end

      AttributeSerializers::ObjectChangesAttribute.
        new(@record.class).
        serialize(changes)

      # We'd like to convert this `HashWithIndifferentAccess` to a plain
      # `Hash`, but we don't, to save memory.
      changes
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant