Convert any groovy script file to a single line script. It is recommended (and also in order for this gem to work) that all lines must be terminated with ;
.
In order to do scripting in ElasticSearch you can pick an handful of languages to inject code in your queries however ElasticSearch requires you that any script is written as a single line of code at query time.
One of the languages supported is Groovy. Groovy is very similar to Java.
GroovyOneliner
was extracted from one of the production apps at HouseTrip. It allows to have a separate file for the Groovy script, which benifits: syntax highlighting, multilines, comments etc... and convert that script into one liner that you can use for queries.
What this gem won't do for you?
- Check if there is any syntax errors
- Check if you hate semi-colons
What does it actually do?
- Removes all
//
&\* ... */
comments - Attempts to remove as much white space as possible such as empty lines, between
;
, etc..
Some file examples and the corresponding output when using this gem:
// This line is amazing
a = 1;
/*
* Foo
*/
b = 2;
Converts to
a = 1;b = 2;
Add this line to your application's Gemfile:
gem 'groovy_oneliner'
And then execute:
$ bundle
Or install it yourself as:
$ gem install groovy_oneliner
Simplest case
GroovyOneliner.compute(path: 'path/to/file')
You can also concat files
GroovyOneliner.compute(path: ['path/to/file1', 'path/to/file2'])
If you want to cache reading the file (recommended for production & staging environments)
GroovyOneliner.compute(path: 'path/to/file', cache: true)
You can also set the cache at class level
GroovyOneliner.always_cache = true
GroovyOneliner.compute(path: 'path/to/file')
- Fork it ( https://github.com/pedrocunha/groovy_oneliner/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request