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

Transforms ERB hash keys to symbol, in case string #833

Merged
merged 2 commits into from
Sep 26, 2020

Conversation

z1lk
Copy link
Contributor

@z1lk z1lk commented Sep 25, 2020

Passing an ERB hash with string keys was causing a NameError in
struct cache initialization, as Struct members must be symbols.
The NameError was being rescued and re-raised, saying the cassette
"references undefined variable", which was misleading.

Passing an ERB hash with string keys was causing a NameError in
struct cache initialization, as Struct members must be symbols.
The NameError was being rescued and re-raised, saying the cassette
"references undefined variable", which was misleading.
Comment on lines 43 to 45
attributes.map!(&:to_sym)
hash[attributes] = Struct.new(*attributes)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
attributes.map!(&:to_sym)
hash[attributes] = Struct.new(*attributes)
end
hash[attributes] = Struct.new(*attributes.map(&:to_sym))
end

Comment on lines +43 to +45
attributes = attributes.map(&:to_sym)
hash[attributes] = Struct.new(*attributes) unless hash.key?(attributes)
hash[attributes]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krainboltgreene Your suggested change got me thinking about reducing the number of keys in the cache. All of the following end up creating Structs with the same members and should reuse the cached Struct rather than create a new one:

@@struct_cache[ [:a, :b] ]
@@struct_cache[ [:a, 'b'] ]
@@struct_cache[ ['a', :b] ]
@@struct_cache[ ['a', 'b'] ]

@krainboltgreene krainboltgreene merged commit 60aaecc into vcr:master Sep 26, 2020
@z1lk z1lk deleted the erb-renderer-support-string-keys branch September 26, 2020 14:00
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

Successfully merging this pull request may close these issues.

None yet

2 participants