Lockbox.default_options = {encode: false} not working, it's being overwritten
Hi, I noticed that setting Lockbox.default_options = {encode: false} is not having any effect and is being overwritten when merging default_options with a default encode: true. This is my research:
https://github.com/ankane/lockbox/blob/4b3dba50bd459ef90cef15ddb0aafe879c60214e/lib/lockbox/model.rb#L53
If encode option is not set it will set encode: true by default, resulting in:
{:attribute=>"email", :encrypted_attribute=>"email_ciphertext", :encode=>true}
Then: https://github.com/ankane/lockbox/blob/4b3dba50bd459ef90cef15ddb0aafe879c60214e/lib/lockbox/encryptor.rb#L1-L7
If my settings are:
Lockbox.default_options = { encode: false }
Lockbox.default_options.merge(options) will result in:
{:encode=>true, :key=>"y\xC4[g\x81\xB7Sjz{m\x15I0\xE5\xD3G\x14y\x2F\r[\xBC{p\xB0M\xD1h\xF0\t\xC4"}
So encode: false is being overwritten and not taken into consideration.
Hey @pjmartorell, nice find and debugging. A fix should be straightforward, but my worry is it'll break apps that rely on the current behavior (likely without realizing it).
I think it may be good to change how default options work, as I think it makes since to have a global option for algorithm but probably not for encode. It may be better to split it out into separate options and deprecate default_options.
Lockbox.default_attribute_options = {}
Lockbox.default_file_options = {}
Let me know what you think. I've removed the example from the readme since it doesn't work for now.
Added a separate option for this in the commit above.
Lockbox.encode_attributes = false
Sorry this took so long to resolve.