Module: Sia

Extended by:
Configurable
Defined in:
lib/sia.rb,
lib/sia/lock.rb,
lib/sia/safe.rb,
lib/sia/error.rb,
lib/sia/version.rb,
lib/sia/persisted_config.rb

Overview

Encrypt files with digital safes

Defined Under Namespace

Modules: Configurable Classes: Error, Lock, PersistedConfig, Safe

Constant Summary collapse

VERSION =
"0.1.0"

Constants included from Configurable

Configurable::DEFAULTS

Class Method Summary collapse

Methods included from Configurable

options

Class Method Details

.config(**opt) ⇒ Hash

Configure Sia, returning the final options

Sia.config(
  root_dir: '/path/to/the/safes/',
  index_name: 'my_index',
  buffer_bytes: 2048,
)
# => {:root_dir=>"/path/to/the/safes/", :index_name=>"my_index", ...}

Allows partial or piecemeal configuration.

Sia.options
# => {:root_dir=>"~/.sia_safes"", :index_name=>".sia_index", ...}

Sia.config(root_dir: '/new_dir')
# => {:root_dir=>"/new_dir", :index_name=>".sia_index", ...}

Sia.config(index_name: 'my_index')
# => {:root_dir=>"/new_dir", :index_name=>"my_index", ...}

See Sia::Configurable::DEFAULTS for all available options.

Parameters:

  • opt (Hash)

Returns:

  • (Hash)

See Also:



46
47
48
49
# File 'lib/sia.rb', line 46

def config(**opt)
  @options.merge!(clean_options(opt))
  options
end

.persist!Object

Persist the current Sia-wide options

The next time Sia is loaded it will use the current config values. Consequently, all new safes will use the current configuration as defaults.



57
58
59
# File 'lib/sia.rb', line 57

def persist!
  PersistedConfig.new.persist(options)
end

.set_default_options!(*specifics, source: :persisted) ⇒ Hash

Note:

This change is not persisted.

Reset the options to default and return the options

Sia.config(root_dir: '/hi', index_name: 'there')
# => {:root_dir=>'/hi', :index_name=>'there', ...}
Sia.set_default_options!
# => {:root_dir=>"~/.sia_safes", :index_name=>".sia_index", ...}

With arguments, resets only the option(s) provided

Sia.config(root_dir: '/hi', index_name: 'there')
# => {:root_dir=>'/hi', :index_name=>'there', ...}
Sia.set_default_options!(:index_name)
# => {:root_dir=>'/hi', :index_name=>".sia_index", ...}

Optionally takes a :source keyword argument that determines whether the default values should be taken from the gem or from the persisted config. Values should be either :persisted or :gem. Default is :persisted. If there is no persisted config the gem defaults are used.

Parameters:

  • specifics (Array<Symbol>)

    Optionally reset only specific options

  • source (:persisted|:gem) (defaults to: :persisted)

    Load defaults from gem or persisted config

Returns:

  • (Hash)

    The new options



87
88
89
90
91
92
# File 'lib/sia.rb', line 87

def set_default_options!(*specifics, source: :persisted)
  specifics = DEFAULTS.keys if specifics.empty?
  keepers = (@options || {}).slice(*DEFAULTS.keys - specifics)
  @options = defaults(source).merge(keepers)
  options
end