Skip to content

Conversation

@JamesChevalier
Copy link

A simpler solution to #271 ... replaces #272

omniauth ultimately defines options as a Hashie::Mash not a Hash:
https://github.com/omniauth/omniauth/blob/master/lib/omniauth/strategy.rb#L547
https://github.com/omniauth/omniauth/blob/master/lib/omniauth/key_store.rb#L5

While Hashie::Mash does implement transform_keys, it does not behave the same way as the Hash implementation does:

Hashie::Mash.new(one: "1", two: "2").transform_keys(&:to_sym)
{"one"=>"1", "two"=>"2"}

Hashie::Mash.new(one: "1", two: "2").to_hash.transform_keys(&:to_sym)
=> {:one=>"1", :two=>"2"}

Setting the default_options to indifferent access lets the two hashes merge properly:

irb(main):001:0> hh = {one: '1', two: '2'}
=> {:one=>"1", :two=>"2"}
irb(main):002:0> hm = Hashie::Mash.new(one: "one", two: "two")
=> {"one"=>"1", "two"=>"2"}
irb(main):003:0> mm = hh.merge(hm)
=> {:one=>"1", :two=>"2", "one"=>"one", "two"=>"two"}
irb(main):004:0> hh = {one: '1', two: '2'}.with_indifferent_access
=> {"one"=>"1", "two"=>"2"}
irb(main):005:0> mm = hh.merge(hm)
=> {"one"=>"one", "two"=>"two"}
irb(main):006:0> mm[:one]
=> "one"

@xtagon
Copy link
Contributor

xtagon commented Aug 24, 2022

Wouldn't this introduce a dependency on ActiveSupport?

@JamesChevalier
Copy link
Author

Wouldn't this introduce a dependency on ActiveSupport?

🤦 Yes, it would. I didn’t realize that’s where it came from & my entire interaction with this gem is within Rails.
So it seems like my other pull request might be the better path forward - #272

@JamesChevalier JamesChevalier deleted the patch-2 branch August 24, 2022 20:12
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.

2 participants