ankane / lockbox

Modern encryption for Ruby and Rails
MIT License
1.44k stars 68 forks source link

Doesnt work with super #142

Closed sirwolfgang closed 2 years ago

sirwolfgang commented 2 years ago

I think due to the way this hooks with define_method, it can cause issues with super overriding it instead of extending it.

class Person < ApplicationRecord
  encrypts :name

  def name
    super 
  end
end

person.name => nil

I haven't dug deep into what all is going on, but you might be able to generate the methods inside of a module then Prepend that module into the model so that super be used as the method's inheritance stack is intact. Short of that, I would make sure to call this out in the documentation.

ankane commented 2 years ago

Hey @sirwolfgang, overridding Lockbox methods isn't supported, but you can try something like this if you need it: https://github.com/ankane/lockbox/issues/117#issuecomment-832406639

sirwolfgang commented 2 years ago

~I got it working the classic alias chaining.~ Edit: Needed to prepend to deal with AR loading columns from database