serpapi / turbo_tests

Run RSpec tests on multiple cores. Like parallel_tests but with incremental summarized output. Originally extracted from the Discourse and Rubygems source code.
https://rubygems.org/gems/turbo_tests
MIT License
173 stars 25 forks source link

Remove OpenStruct usage with Struct replacement #53

Closed javierjulio closed 4 months ago

javierjulio commented 4 months ago

This replacement to use a struct should still resolve the original issue in #49 but also with https://github.com/serpapi/turbo_tests/pull/49#issuecomment-2057132440 for the reported ruby core issue.

Example you can try in an IRB console:

data = {
  a: 1,
  b: 2,
  c: {
    d: 3,
    e: {
      f: 4,
      g: 5
    }
  }
}

class Hash
  def to_struct
    Struct.new(*self.keys).new(*self.values.map { |value| value.is_a?(Hash) ? value.to_struct : value })
  end
end

result = data.to_struct
javierjulio commented 4 months ago

Since #49 also introduced the json gem dependency, I believe that can be removed here since OpenStruct is no longer used. If desired, I can remove the gemspec dependency here.

deivid-rodriguez commented 4 months ago

Nice! I don't know the root cause of the ruby-core issue, but this direction feels like a nice regardless.

javierjulio commented 4 months ago

@ilyazub you're welcome and thank you! That sounds good if it's not needed then.