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
Property named required no longer works #276
Comments
I was able to use reflection to find all the private methods that could conflict with property names. I basically found this via: class DashWithAllExtensions < Hashie::Dash
Hashie::Extensions.constants.map do | c |
include Hashie::Extensions.const_get(c)
end
Hashie::Extensions::Dash.constants.map do | c |
include Hashie::Extensions::Dash.const_get(c)
end
Hashie::Extensions::Mash.constants.map do | c |
include Hashie::Extensions::Mash.const_get(c)
end
# Is this not includable?
# Hashie::Extensions::Parsers.constants.map do | c |
# include Hashie::Extensions::Mash.const_get(c)
# end
end
names_that_are_unnecessarily_reserved = (DashWithAllExtensions.new.private_methods - Object.new.private_methods).map do | name |
next if name.to_s.start_with? '___'
name.to_s.gsub(/\!\Z/, '').gsub(/\?\Z/, '').gsub(/=\Z/, '')
end.uniq The names I found are: It seems unlikely that any of these would be used as property names other than I am also planning to add a test that ensures that any public methods defined by Hashie extensions are reserved and cannot be used as property names, but the property :zip # raises exception saying the property would override a reserved method and may cause unexpected behavior
property :zip, allow_override: true # ok |
I like this idea. I picked a double underscore for the MethodOverridingWriter extension, so I think it should be standardized in that extension for sure. Off the top of my head I'm not sure what the other extensions use. Regarding the |
I have a branch with most of the work done to:
I haven't submitted a PR yet because I'm not really sure about the best way to handle the last item. Apparently Hashie used to have this message: That's basically how I feel about using a field like Note: tried it out... I guess key is okay because Hashie::Dash doesn't seem to get Mash's '?' methods, but class is an issue: class DashWithClass < Hashie::Dash
property :class
end
DashWithClass.new(class: 'foo')
# SystemStackError: stack level too deep That would be annoying to find in a large code base, especially since it's tricky to get a stacktrace for However, a warning isn't really going to help, and raising an error would be a breaking change since Hashie has allowed that those fields in the past and explicitly allows them with Another related idea is to allow those fields to be defined but without Mash-like methods. So you'd still be allowed to have a field named |
any news? |
According to d03759f#commitcomment-10090931 this was fixed? @maxlinc? |
I had been using a dash with a
:required
property. It worked fine in Hashie v3.3.2. It stopped working in v3.4.0.The issue seems to be that Hashie is trying to define two conflicting
required?
methods. The first one is the Mash-like behavior to check if the value of the property is truthy that has always been part of Hashie Mash/Dash. The second is to check if a property is required that appears to have been introduced in #252.The result is a very tricky to debug error:
Note that a class-level method named
required?
did exist and should be okay, because the Mash-like methods only exist at the instance level.I'm hoping to see support for restored for
required
so I don't have to resort to workarounds to define the Swagger Parameter object in a Dash, but it would probably be good to add a list of reserved names to Dash and to avoid introducing any new instance-level methods. I suggest prefixing all internal methods with some common prefix, but I'm not sure what to use since underscore and double-underscore already have meaning in Hashie.The text was updated successfully, but these errors were encountered: