-
Notifications
You must be signed in to change notification settings - Fork 34
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
HashWithIndifferentCaseInsensitiveAccess does not retain original case #98
Comments
I have patched # scimitar_patches.rb
module Scimitar
module Support
class HashWithIndifferentCaseInsensitiveAccess < ActiveSupport::HashWithIndifferentAccess
class CIString < String
attr_reader :original
def initialize(key)
@original = key
super(key.downcase)
end
end
delegate :as_json, to: :to_hash
def to_hash
super.transform_keys do |key|
key.is_a?(CIString) ? key.original : key
end
end
private
if Symbol.method_defined?(:name)
def convert_key(key)
case key
when String then CIString.new(key)
when Symbol then CIString.new(key.name)
else key
end
end
else
def convert_key(key)
case key
when String, Symbol then CIString.new(key.to_s)
else key
end
end
end
end
end
end Now it is possible to retrieve the hash with the original keys (though as strings, like # name is written to a jsonb column
def name=(value)
super(value.as_json)
end
# addresses is written to a jsonb[] column
def addresses=(value)
super(value.as_json)
end I'd be happy to open a PR to get this upstream if you are interested. |
@pond Is this something you would consider adding to Scimitar? |
@s-andringa Yes, I've just been a bit sick & had no sleep going into this week (stress + overwork issues) so I've not been very "functional". Haven't looked into how big a CPU / RAM hit this kind of thing would do. Conceptually OK, I just wanted to verify the implementation. |
I'm sorry to hear that. No worries, it's working for us with the patch, there's no rush. I just had some time on my hands for a PR so wanted to make sure you'd be on board. You take care of yourself, your well-being comes first! |
I've made progress on this. The basic idea is to keep a map of the original keys that the Hash uses, to their converted, string-downcase variants. Overriding Whenever a lookup happens, we lean on an override of RAM overhead is as big as the key-to-key map (not that big) and runtime impact is relatively small, without extra object instantiation etc. for things like internal classes and with the Hash now behaving itself more rationally in terms of self-representation across the system. It doesn't (say) only work when Because of a dramatic amount of yak shaving arising from #109 (ongoing), this may be a few days away yet and will be unavoidably part of a larger body of work. |
This is being addressed in #109 after it came up as an important aspect in tests checking for expected data. |
Here is stated that
However, this doesn't seem to be the case (pun purely coincidental). I have tried a whole bunch of things, but in no case (😉) the original case was returned:
What exactly is meant by "enumeration"? We are storing some complex type attributes straight to a jsonb column (
name
,addresses
), but the original case of the sub-attribute keys is lost there. Which is unfortunate because we would like to expose the value with the original case when the resource is requested. (I know it shouldn't make a difference for SCIM clients, but losing the case merely because of a side effect of case insensitive lookup and comparison still seems undesirable.)Am I missing something?
The text was updated successfully, but these errors were encountered: