Class: Cryptoform::Config::StateConfigBuilder
- Inherits:
-
Object
- Object
- Cryptoform::Config::StateConfigBuilder
- Defined in:
- lib/cryptoform/config/state_config_builder.rb
Constant Summary collapse
- Config =
Data.define(:storage_backend, :encryption_backend)
- STORAGE_BACKENDS =
{ file: Cryptoform::StorageBackends::File }.freeze
- ENCRYPTION_BACKENDS =
{ lockbox: Cryptoform::EncryptionBackends::Lockbox, diff_lockbox: Cryptoform::EncryptionBackends::DiffLockbox }.freeze
Instance Method Summary collapse
- #config ⇒ Object
- #encryption_backend(name, **params) ⇒ Object
-
#initialize(name) ⇒ StateConfigBuilder
constructor
A new instance of StateConfigBuilder.
- #storage_backend(name, **params) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(name) ⇒ StateConfigBuilder
Returns a new instance of StateConfigBuilder.
15 16 17 18 19 |
# File 'lib/cryptoform/config/state_config_builder.rb', line 15 def initialize(name, &) @name = name instance_exec(&) end |
Instance Method Details
#config ⇒ Object
35 36 37 |
# File 'lib/cryptoform/config/state_config_builder.rb', line 35 def config Config.new(@storage_backend, @encryption_backend) end |
#encryption_backend(name, **params) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/cryptoform/config/state_config_builder.rb', line 28 def encryption_backend(name, **params) name = name.to_sym raise ArgumentError, "unknown encryption backend #{name}" unless ENCRYPTION_BACKENDS.key?(name) @encryption_backend = ENCRYPTION_BACKENDS[name].new(@name, **params) end |
#storage_backend(name, **params) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/cryptoform/config/state_config_builder.rb', line 21 def storage_backend(name, **params) name = name.to_sym raise ArgumentError, "unknown storage backend #{name}" unless STORAGE_BACKENDS.key?(name) @storage_backend = STORAGE_BACKENDS[name].new(@name, **params) end |
#validate! ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/cryptoform/config/state_config_builder.rb', line 39 def validate! if @storage_backend.nil? raise Cryptoform::ConfigValidationError, "storage backend must be specified for state '#{@name}'" end return unless @encryption_backend.nil? raise Cryptoform::ConfigValidationError, "encryption backend must be specified for state '#{@name}'" end |