hashid-rails icon indicating copy to clipboard operation
hashid-rails copied to clipboard

Avoid Clobbering the Config's Pepper Value

Open klondikemarlen opened this issue 2 years ago • 3 comments

The original code was always overriding the "pepper" value with table_name, so it didn't matter what you set that value to in the config. The config's "pepper" value should be respected.

klondikemarlen avatar Jul 09 '22 23:07 klondikemarlen

I didn't quite think this through, I'll throw up proper solution (that doesn't fail all the tests) quite soon.

klondikemarlen avatar Jul 10 '22 01:07 klondikemarlen

The config now supports setting the pepper as a Proc and evaluating it on the class. Plus now all the tests pass! :stuck_out_tongue:.

This has the advantage that you can now both disable your pepper, and make your pepper much more complex. i.e.

# Call a custom "pepper" method defined on the class
Hashid::Rails.configure do |config|
  config.pepper = ->(klass) { klass.pepper } 
end

# Disable pepper altogether.
Hashid::Rails.configure do |config|
  config.pepper = nil
end

klondikemarlen avatar Jul 10 '22 02:07 klondikemarlen

Can this be merged? :-)

cseelus avatar Jun 23 '23 03:06 cseelus