Sha256: 435a46510b8de6f77079523963be7db04e000f3f00da5cb1c38e74827782de33
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true # Trocla::Encryptions class Trocla::Encryptions # Base class Base attr_reader :trocla, :config def initialize(config, trocla) @trocla = trocla @config = config end def encrypt(_) raise NoMethodError.new("#{self.class.name} needs to implement 'encrypt()'") end def decrypt(_) raise NoMethodError.new("#{self.class.name} needs to implement 'decrypt()'") end end class << self def [](enc) encryptions[enc.to_s.downcase] end def all Dir[path '*'].collect do |enc| File.basename(enc, '.rb').downcase end end def available?(encryption) all.include?(encryption.to_s.downcase) end private def encryptions @@encryptions ||= Hash.new do |hash, encryption| encryption = encryption.to_s.downcase if File.exist?(path encryption) require "trocla/encryptions/#{encryption}" class_name = "Trocla::Encryptions::#{encryption.capitalize}" hash[encryption] = (eval class_name) else raise "Encryption #{encryption} is not supported!" end end end def path(encryption) File.expand_path( File.join(File.dirname(__FILE__), 'encryptions', "#{encryption}.rb") ) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
trocla-0.5.1 | lib/trocla/encryptions.rb |
trocla-0.5.0 | lib/trocla/encryptions.rb |