I have the following doll example pattern:
{ "servers" : [ { "port" : 9200, "host" : "localhost", "queries" : [ <% @markets.each do |market| -%> { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ], "obj" : "solr/market_<%= market %>:type=queryResultCache,id=org.apache.solr.search.LRUCache", "attr" : [ "hits","hitratio" ] }, <% end -%> ], "numQueryThreads" : 2 } ], }
Applying it with market = ['UK', 'FR', 'IT'], I get the following:
{ "servers" : [ { "port" : 9200, "host" : "localhost", "queries" : [ { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ], "obj" : "solr/market_UK:type=queryResultCache,id=org.apache.solr.search.LRUCache", "attr" : [ "hits","hitratio" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ], "obj" : "solr/market_FR:type=queryResultCache,id=org.apache.solr.search.LRUCache", "attr" : [ "hits","hitratio" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ], "obj" : "solr/market_IT:type=queryResultCache,id=org.apache.solr.search.LRUCache", "attr" : [ "hits","hitratio" ] }, ], "numQueryThreads" : 2 } ], }
The problem is the last comma, which makes it an invalid solr configuration.
Instead of using market.each, I could use market.map and join (','). but how to use the card in this case?
I can use the card as follows:
<%= @markets.map{ |market| "hello_"+market }.join(',') -%>
this will print hello_UK,hello_FR,hello_IT (note that we do not have a comma after hello_IT), but I need something like this:
{ "servers" : [ { "port" : 9200, "host" : "localhost", "queries" : [ <% @markets.map |market| -%> { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.StdOutWriter" } ], "obj" : "solr/market_<%= market %>:type=queryResultCache,id=org.apache.solr.search.LRUCache", "attr" : [ "hits","hitratio" ] }, <% }.join(',') -%> ], "numQueryThreads" : 2 } ], }
this does not work.
so how to make it work? or how to change my puppet pattern to remove the last comma?