What is the difference between eruby and erb? What considerations prompted me to choose this or that?
My application creates configuration files for network devices (routers, load balancers, firewalls, etc.). My plan is to create template configuration files using the built-in ruby โโ(via eruby or erb) in the source files to do things like iteratively generate all the interface configuration blocks for the router (all of these blocks are very similar, they differ only label and IP address). For example, I may have a configuration template file, for example:
hostname sample-router <%= r = String.new; [ ["GigabitEthernet1/1", "10.5.16.1"], ["GigabitEthernet1/2", "10.5.17.1"], ["GigabitEthernet1/3", "10.5.18.1"] ].each { |tuple| r << "interface #{tuple[0]}\n" r << " ip address #{tuple[1]} netmask 255.255.255.0\n" } r.chomp %> logging 10.5.16.26
which, when launched through the built-in Ruby interpreter (erb or eruby), produces the following output:
hostname sample-router interface GigabitEthernet1/1 ip address 10.5.16.1 netmask 255.255.255.0 interface GigabitEthernet1/2 ip address 10.5.17.1 netmask 255.255.255.0 interface GigabitEthernet1/3 ip address 10.5.18.1 netmask 255.255.255.0 logging 10.5.16.26
source share