Fix issue with hashes not being indifferent access if available on document property build#181
Fix issue with hashes not being indifferent access if available on document property build#181ErickFabian wants to merge 1 commit into3.1from
Conversation
…cument property build
|
|
||
| def [](key) | ||
| return detect {|property| property.key == key } if key.is_a?(Symbol) | ||
| super |
There was a problem hiding this comment.
[] does not exist in Set
|
|
||
| def custom_class(value) | ||
| value = value.is_a?(Hash) ? value.symbolize_keys : value | ||
| value = value.is_a?(Hash) ? hash_with_indifferent_access_value(value) : value |
There was a problem hiding this comment.
do we want to change a explicit hash value to a HashWithI...?? this sound shady
There was a problem hiding this comment.
right, its explicit it should keep that value and not be changed
There was a problem hiding this comment.
In your sample with contracts in School is contracts defined in properties as HashorHashWithIndifferentAccess` ?
There was a problem hiding this comment.
but this means changing all models to use HashWith... in the class_name.
There was a problem hiding this comment.
its defined as property :contracts, class_name: Hash, default: Hash.new
There was a problem hiding this comment.
now that i think about it, dolly is already changing hashes to HashWithIndifferent, this was just missing that transformation.
There was a problem hiding this comment.
you are right, but then this is weird... as there will be cases where it makes more sense a Hash, and we are force-casting that property to HWIA, right now the default is HWIF, for all data that comes in, but properties are casted to the class that we set on the property method, that way people con define the right type for the property they want. Force casting Hash to HWIA, even if the document is parsed as such is confusing...
There was a problem hiding this comment.
If I do property :foo, class_name: Hash I will expect a Hash, not a HashWithINdifferentAccess, and yeah If you want to use HWIA you need to set it as such.
I wonder how Rails work with this...
There was a problem hiding this comment.
But, then again, a HWIA is a Hash, and dolly is setting now everything as string keys by default, so ok... I guess we can use this. Just want to tested on BS and some other projects that sue newer dolly and see if there arent any side effects
| module FrameworkHelper | ||
| def rails? | ||
| defined?(ActiveSupport::HashWithIndifferentAccess) | ||
| !!defined?(ActiveSupport::HashWithIndifferentAccess) |
## Previous
## After