Class: ReliableMsg::Config

Inherits:
Object show all
Defined in:
lib/ap4r/queue_manager_ext.rb

Overview

Dynamic configuration with ERb

Some times you would like to inject dynamic values into your configuration file. In these cases, you can mix ERb in with your YAML to code some logic, like:

<% acl = [] %> <% for i in 1..100 %> <% acl << “192.168.0.#i” %> <% end %> acl: <%= acl.map{|ip| “allow #{ip}”}.join(‘ ’)

Instance Method Summary collapse

Instance Method Details

#load_no_createObject

– TODO: should enhance YAML.load_documents instead of this method?, 2007/5/7 kato-k



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ap4r/queue_manager_ext.rb', line 39

def load_no_create
  if File.exist?(@file)
    @config= {}
    File.open @file, "r" do |input|
      YAML.load_documents(erb_render(input.read)) do |doc|
        @config.merge! doc
      end
    end
    true
  end
end

#load_no_create_originalObject



34
# File 'lib/ap4r/queue_manager_ext.rb', line 34

alias :load_no_create_original :load_no_create

#load_or_createObject

– TODO: should enhance YAML.load_documents instead of this method?, 2007/5/7 kato-k



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ap4r/queue_manager_ext.rb', line 53

def load_or_create
  if File.exist?(@file)
    @config= {}
    File.open @file, "r" do |input|
      YAML.load_documents(erb_render(input.read)) do |doc|
        @config.merge! doc
      end
    end
    @logger.info format(INFO_LOADED_CONFIG, @file)
  else
    @config = {
      "store" => DEFAULT_STORE,
      "drb" => DEFAULT_DRB
    }
    save
    @logger.info format(INFO_CREATED_CONFIG, @file)
  end
end

#load_or_create_originalObject



35
# File 'lib/ap4r/queue_manager_ext.rb', line 35

alias :load_or_create_original :load_or_create