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

Ensure that object cloning works #34

Open
silug opened this issue Dec 4, 2024 · 2 comments
Open

Ensure that object cloning works #34

silug opened this issue Dec 4, 2024 · 2 comments

Comments

@silug
Copy link
Contributor

silug commented Dec 4, 2024

Previously copying a ComplianceEngine::Data object (with Marshal.dump and Marshal.load) worked, but at some point that changed. We need to

  1. Make that (or something like that) work again
  2. Add tests for this
@silug
Copy link
Contributor Author

silug commented Dec 4, 2024

After some testing, it seems like calling clone on a ComplianceEngine::Data works well enough.

I'm going to leave this open until we verify.

@silug
Copy link
Contributor Author

silug commented Dec 4, 2024

If we need to do a custom clone (or maybe intialize_copy) method, it looks like something like this should work:

copy = ComplianceEngine::Data.new(*self.data.map { |_,v| v[:loader] })
(self.context_variables + self.cache_variables).each do |var|
  value = self.instance_variable_get(var)
  next if value.nil?
  if value.is_a?(Hash)
    copy.instance_variable_set(var, Marshal.load(Marshal.dump(value)))
  else
    copy.instance_variable_set(var, value.dup)
  end
end
copy

@silug silug moved this from New to Todo in Org Triage Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant