Class: RBarman::Configuration
- Inherits:
-
Object
- Object
- RBarman::Configuration
- Includes:
- Singleton
- Defined in:
- lib/rbarman/configuration.rb
Overview
A very flexible configuration class, to be used as Singleton
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Gives access to parameters.
-
#[]=(key, value) ⇒ void
Adds a new parameter.
-
#basic_configuration ⇒ void
adds
:binarywith path to barman binary as value and:barman_home(default $HOME) with path to barman’s backup base directory as value. -
#initialize(data = {}) ⇒ Configuration
constructor
Creates a new instance of Configuration.
-
#method_missing(sym, *args) ⇒ Object, ...
For catching [NoMethodError] and trying to add a new parameter or returning a parameter value, based on the “missing” method name.
-
#update!(data) ⇒ void
Adds parameters.
Constructor Details
#initialize(data = {}) ⇒ Configuration
Creates a new instance of RBarman::Configuration
11 12 13 14 15 |
# File 'lib/rbarman/configuration.rb', line 11 def initialize(data={}) @data = {} update!(data) basic_configuration end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object, ...
For catching [NoMethodError] and trying to add a new parameter or returning a parameter value, based on the “missing” method name
55 56 57 58 59 60 61 |
# File 'lib/rbarman/configuration.rb', line 55 def method_missing(sym, *args) if sym.to_s =~ /(.+)=$/ self[$1] = args.first else self[sym] end end |
Instance Method Details
#[](key) ⇒ Object?
Gives access to parameters
29 30 31 |
# File 'lib/rbarman/configuration.rb', line 29 def [](key) @data[key.to_sym] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Adds a new parameter
37 38 39 40 41 42 43 |
# File 'lib/rbarman/configuration.rb', line 37 def []=(key, value) if value.class == Hash @data[key.to_sym] = Config.new(value) else @data[key.to_sym] = value end end |
#basic_configuration ⇒ void
This method returns an undefined value.
adds :binary with path to barman binary as value and :barman_home (default $HOME) with path to barman’s backup base directory as value. If which reports a path for barman, that path will be used, otherwise /usr/bin/barman
68 69 70 71 72 |
# File 'lib/rbarman/configuration.rb', line 68 def basic_configuration b_path = `which barman`.chomp self[:binary] = b_path.empty? ? '/usr/bin/barman' : b_path self[:barman_home] = ENV['HOME'] end |
#update!(data) ⇒ void
This method returns an undefined value.
Adds parameters
20 21 22 23 24 |
# File 'lib/rbarman/configuration.rb', line 20 def update!(data) data.each do |key, value| self[key] = value end end |