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 · 1 comment
Labels

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
Copy link

This issue has been automatically marked as stale due to inactivity.
The resources of our volunteers are limited.
Bug reports must provide a script that reproduces the bug, using our template. Feature suggestions must include a promise to build the feature yourself.
Thank you for all your contributions.

@github-actions github-actions bot added the Stale label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant