Module: Proctor::Resource::Erb

Instance Method Summary collapse

Instance Method Details

#erb_ify(manager_or_service, service, env) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/proctor/resource/erb.rb', line 36

def erb_ify(manager_or_service, service, env)
  manager_or_service.data.each_pair do |k,v|
    case v
      when String
        manager_or_service.data[k] = ERB.new(v).result(binding)
      when Hash
        manager_or_service.data[k] = erb_ify_hash(v, service, env)
    end
  end
  manager_or_service
end

#erb_ify_hash(hash, service, env) ⇒ Object

private



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/proctor/resource/erb.rb', line 21

def erb_ify_hash(hash, service, env)
  hash.each_pair do |k,v|
    case v
      when String
        begin
        hash[k] = ERB.new(v).result(binding)
        rescue
        end
      when Hash
        hash[k] = erb_ify_hash(v, service, env)
    end
  end
  hash
end

#erb_ify_services(services, env) ⇒ Object



48
49
50
51
52
53
# File 'lib/proctor/resource/erb.rb', line 48

def erb_ify_services(services, env)
  services.each_pair do |key,service|
    service = erb_ify(service, service, env)
  end
  services
end

#generate_group_erb(manager, node, services, template, env) ⇒ Object



79
80
81
82
83
# File 'lib/proctor/resource/erb.rb', line 79

def generate_group_erb(manager, node, services, template, env)
  services = erb_ify_services(services, env)
  erb = ERB.new(File.read(template.path),0,'-')
  erb.result(binding)
end

#generate_group_header(_manager, node, template, env) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/proctor/resource/erb.rb', line 55

def generate_group_header(_manager, node, template, env)
  manager = erb_ify(_manager, node, env)
  xfile = manager.data["node_filename"] || "#{node.name}.conf"
  <<-EOF.gsub('          ','')
    # Config file for #{manager.name}/#{node.name}
    # Generated by Proctor #{Time.now.strftime("on %Y-%m-%d at %H:%M:%S")}
    # Using template: #{template.name}
    #    Export path: #{manager.data["export_directory"]}/#{xfile}
    #  Start command: #{manager.data["start_command"]}
  EOF
end

#generate_service_erb(_manager, _service, template, env) ⇒ Object



85
86
87
88
89
90
# File 'lib/proctor/resource/erb.rb', line 85

def generate_service_erb(_manager, _service, template, env)
  manager = erb_ify(_manager, _service, env)
  service = erb_ify(_service, _service, env)
  erb = ERB.new(File.read(template.path))
  erb.result(binding)
end

#generate_service_header(_manager, service, template, env) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/proctor/resource/erb.rb', line 67

def generate_service_header(_manager, service, template, env)
  manager = erb_ify(_manager, service, env)
  xfile = manager.data["service_filename"] || "#{service.name}.conf"
  <<-EOF.gsub('          ','')
    # Config file for #{manager.name}/#{service.name}
    # Generated by Proctor #{Time.now.strftime("on %Y-%m-%d at %H:%M:%S")}
    # Using template: #{template.name}
    #    Export path: #{manager.data["export_directory"]}/#{xfile}
    #  Start command: #{manager.data["start_command"]}
  EOF
end

#render_group_template(manager, node, services, template, env) ⇒ Object



7
8
9
10
11
# File 'lib/proctor/resource/erb.rb', line 7

def render_group_template(manager, node, services, template, env)
  header = generate_group_header(manager, node, template, env)
  body   = generate_group_erb(manager, node, services, template, env)
  header + body
end

#render_service_template(manager, service, template, env) ⇒ Object



13
14
15
16
17
# File 'lib/proctor/resource/erb.rb', line 13

def render_service_template(manager, service, template, env)
  header = generate_service_header(manager, service, template, env)
  body   = generate_service_erb(manager, service, template, env)
  header + body
end