Class: Configliere::Param

Inherits:
ParamParent show all
Includes:
EncryptedParam
Defined in:
lib/configliere/param.rb,
lib/configliere/encrypted.rb

Overview

Hash of fields to store.

Any field name beginning with ‘decrypted_’ automatically creates a counterpart ‘encrypted_’ field using the encrypt_pass.

Constant Summary

Constants inherited from Hash

Hash::DEEP_MERGER

Instance Attribute Summary

Attributes included from EncryptedParam

#encrypt_pass

Instance Method Summary collapse

Methods included from EncryptedParam

#resolve_encrypted!

Methods inherited from ParamParent

#export

Methods inherited from Hash

#compact, #compact!, #deep_delete, #deep_get, #deep_merge, #deep_merge!, #deep_set, #to_sash

Constructor Details

#initialize(constructor = {}) ⇒ Param

Returns a new instance of Param.

Parameters:

  • constructor (Object) (defaults to: {})

    The default value for the mash. Defaults to an empty hash.



30
31
32
33
34
35
36
37
# File 'lib/configliere/param.rb', line 30

def initialize(constructor = {})
  if constructor.is_a?(Hash)
    super()
    update(constructor) unless constructor.empty?
  else
    super(constructor)
  end
end

Instance Method Details

#[](param) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/configliere/param.rb', line 78

def [] param
  if param =~ /\./
    return deep_get( *convert_key(param) )
  else
    super param
  end
end

#[]=(param, val) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/configliere/param.rb', line 70

def []= param, val
  if param =~ /\./
    return deep_set( *(convert_key(param) | [val]) )
  else
    super param, val
  end
end

#defaults(hsh) ⇒ Object

Incorporates the given settings. alias for deep_merge! Existing values not given in the hash

Examples:

Settings.defaults :hat => :cat, :basket => :lotion, :moon => { :man => :smiling }
Settings.defaults :basket => :tasket, :moon => { :cow => :smiling }
Config  #=> { :hat => :cat, :basket => :tasket, :moon => { :man => :smiling, :cow => :jumping } }

Parameters:

  • hsh

    the defaults to set.



56
57
58
# File 'lib/configliere/param.rb', line 56

def defaults hsh
  deep_merge! hsh
end

#delete(param) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/configliere/param.rb', line 86

def delete param
  if param =~ /\./
    return deep_delete( *convert_key(param) )
  else
    super param
  end
end

#resolve!Object

Finalize and validate params



61
62
63
64
# File 'lib/configliere/param.rb', line 61

def resolve!
  super()
  validate!
end

#to_hashHash

Returns The mash as a Hash with string keys.

Returns:

  • (Hash)

    The mash as a Hash with string keys.



40
41
42
# File 'lib/configliere/param.rb', line 40

def to_hash
  Hash.new(default).merge(self)
end

#use(*args) ⇒ Object



94
95
96
97
98
# File 'lib/configliere/param.rb', line 94

def use *args
  hsh = args.pop if args.last.is_a?(Hash)
  Configliere.use(*args)
  self.deep_merge!(hsh) unless hsh.nil?
end

#validate!Object

Check that all defined params are valid



66
67
68
# File 'lib/configliere/param.rb', line 66

def validate!
  super()
end