lib/sym/crypt/configuration.rb in sym-crypt-1.0.0 vs lib/sym/crypt/configuration.rb in sym-crypt-1.1.1

- old
+ new

@@ -1,5 +1,8 @@ +require 'singleton' +require 'sym/configurable' +require 'ostruct' module Sym module Crypt # This class encapsulates application configuration, and exports # a familiar method +#configure+ for defining configuration in a # block. @@ -19,26 +22,29 @@ # config.private_key_cipher = config.data_cipher # config.compression_enabled = true # config.compression_level = Zlib::BEST_COMPRESSION # end - class Configuration - class << self - attr_accessor :config + class Configuration < OpenStruct - def configure - self.config ||= Configuration.new - yield config if block_given? - end + include Sym::Configurable - def property(name) - self.config.send(name) + class << self + def defaults! + configure(&default_proc) end - end - # See file +lib/sym/crypt.rb+ where these values are defined. + private - attr_accessor :data_cipher, :password_cipher, :private_key_cipher - attr_accessor :compression_enabled, :compression_level + def default_proc + ->(config) do + config.password_cipher = 'AES-128-CBC' + config.data_cipher = 'AES-256-CBC' + config.private_key_cipher = config.data_cipher + config.compression_enabled = true + config.compression_level = Zlib::BEST_COMPRESSION + end + end + end end end end