vendredi 1 avril 2016

Wnat is the best pattern in this case?

I've written simple ruby wrapper for ActiveSupport::MessageEncryptor, but this OOP design seems not good enough for me:

module StringEncryptor
  class << self
    def decrypt(secret, string, *signature_key_or_options)
      crypt(secret, *signature_key_or_options).decrypt_and_verify(string)
    end

    def encrypt(secret, string, *signature_key_or_options)
      crypt(secret, *signature_key_or_options).encrypt_and_sign(string)
    end

    private

    def crypt(secret, *signature_key_or_options)
      crypt = ActiveSupport::MessageEncryptor.new(secret, *signature_key_or_options)
    end
  end
end

Any ideas to make this code prettier?(maybe replace the private method with class variable or something else...)

Aucun commentaire:

Enregistrer un commentaire