Class: Jerakia::Encryption

Inherits:
Object
  • Object
show all
Defined in:
lib/jerakia/encryption.rb,
lib/jerakia/encryption/vault.rb

Defined Under Namespace

Modules: Vault

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider = nil) ⇒ Encryption


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jerakia/encryption.rb', line 14

def initialize(provider=nil)
  if provider.nil?
    provider = config["provider"]
  end

  return nil if provider.nil?

  begin
    require "jerakia/encryption/#{provider}"
  rescue LoadError => e
    raise Jerakia::Error, "Failed to load encryption provider #{provider}"
  end

  begin
    eval "extend Jerakia::Encryption::#{provider.capitalize}"
  rescue NameError => e
    raise Jerakia::Error, "Encryption provider #{provider} did not provide class"
  end
  @loaded = true
end

Instance Attribute Details

#loadedObject (readonly)

Returns the value of attribute loaded


12
13
14
# File 'lib/jerakia/encryption.rb', line 12

def loaded
  @loaded
end

Class Method Details

.configObject


50
51
52
# File 'lib/jerakia/encryption.rb', line 50

def self.config
  Jerakia.config[:encryption] || {}
end

.handlerObject


7
8
9
# File 'lib/jerakia/encryption.rb', line 7

def handler
  @handler || @handler = self.new
end

Instance Method Details

#configObject


54
55
56
# File 'lib/jerakia/encryption.rb', line 54

def config
  self.class.config
end

#features?(feature) ⇒ Boolean


39
40
41
42
43
44
45
46
47
48
# File 'lib/jerakia/encryption.rb', line 39

def features?(feature)
  case feature
  when :encrypt
    respond_to?('encrypt')
  when :decrypt
    respond_to?('decrypt')
  else
    false
  end
end

#loaded?Boolean


35
36
37
# File 'lib/jerakia/encryption.rb', line 35

def loaded?
  loaded
end