Skip to content

Defined methods in an anonymous module #99

@tpickett66

Description

@tpickett66

Would the maintainers be open to a pull request moving the generated methods to either an anonymous or usefully named module similar to state_machine. This would allow for end users to more easily manipulate the execution path on these methods. In my particular instance I'd like to be able to rescue from errors raised in the decryption process and handle them in an application specific manner.

With the current implementation we would have to do something like:

class User
  attr_encrypted :email

  def email_rescuing_errors
    email_raising_errors
  rescue AttrEncrypted::Errors::Error
    self.email = nil
  end
  alias_method :email_raising_errors, :email
  alias_method :email, :email_rescuing_errors
end

But with a module inserted in the inheritance chain we could simplify things quite a bit:

class User
  attr_encrypted :email

  def email
    super
  rescue AttrEncrypted::Errors::Error
    self.email = nil
  end
end

Additionally I suspect it could simplify the implementation of custom (en|de)cryptors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions