Last active
December 16, 2015 00:39
-
-
Save tmiller/5349102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/cryptography_adapter.rb | |
# Parent adapter class | |
class CryptographyAdapter | |
def encrypted?(data) | |
raise "Method not implmented" | |
end | |
def decrypt(data) | |
raise "Method not implmented" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/cryptography.rb | |
Cryptography::cryptography_klass = CryptographyAdapter::GPG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/cryptography.rb | |
# Public interface for your encryption and decryption needs | |
class Cryptography | |
cattr_accessor :cryptography_klass | |
attr_reader :crypto | |
def initialize() | |
@crypto = self.class.cryptography_klass.new | |
end | |
def encrypted?(data) | |
@crypto.encrypted?(data) | |
end | |
def decrypt(data) | |
@crypto.decrypt(data) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/cryptography_adapter/gpg.rb | |
# Used in production | |
class CryptographyAdapter::GPG < CryptographyAdapter | |
def encrypted?(data) | |
# Return true for encrypted data | |
end | |
def decrypt(data) | |
# Decrypt some data | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/cryptography_adapter/rot13.rb | |
# Used in tests | |
class CryptographyAdapter::ROT13 < CryptographyAdapter | |
def encrypted?(data) | |
# Return true for encrypted data | |
end | |
def decrypt(data) | |
# Decrypt some data | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test/test_helper.rb | |
Cryptography::cryptography_klass = CryptographyAdapter::ROT13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment