Sha256: c8a7ea6301e6c78a99e44d4da9aefd02eb08b7ea89695230b636466e2683a9fc

Contents?: true

Size: 1.55 KB

Versions: 4

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'chamber/configuration'
require 'chamber/file_set'
require 'chamber/settings'

module  Chamber
class   Instance
  attr_accessor :configuration,
                :files

  def initialize(options = {})
    self.configuration = Configuration.new  options
    self.files         = FileSet.new        configuration.to_hash
  end

  def settings
    @settings ||= files.to_settings { |settings| @settings = settings }
  end

  def filenames
    files.filenames
  end

  def secure
    files.secure
  end

  def sign
    files.sign
  end

  def verify
    files.verify
  end

  def encrypt(data, options = {})
    config = configuration.to_hash.merge(options)

    Settings.
      new(
      config.merge(
        settings:     data,
        pre_filters:  [Filters::EncryptionFilter],
        post_filters: [],
      ),
    ).
      to_hash
  end

  def decrypt(data, options = {})
    config = configuration.to_hash.merge(options)

    Settings.
      new(
      config.merge(
        settings:     data,
        pre_filters:  [Filters::NamespaceFilter],
        post_filters: [
                        Filters::DecryptionFilter,
                        Filters::FailedDecryptionFilter,
                      ],
      ),
    ).
      to_hash
  end

  def to_s(options = {})
    settings.to_s(options)
  end

  def method_missing(name, *args)
    return settings.public_send(name, *args) if settings.respond_to?(name)

    super
  end

  def respond_to_missing?(name, include_private = false)
    settings.respond_to?(name, include_private)
  end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chamber-2.12.3 lib/chamber/instance.rb
chamber-2.12.2 lib/chamber/instance.rb
chamber-2.12.1 lib/chamber/instance.rb
chamber-2.12.0 lib/chamber/instance.rb