0.0
No commit activity in last 3 years
No release in over 3 years
Convert groovy scripts into one line script
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 2.9
~> 0
~> 10.0
~> 3
 Project Readme

GroovyOneliner

Build Status Code Climate

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 ;.

What would this help 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:

Example

// This line is amazing
a = 1;

/*
 * Foo
 */
b = 2;

Converts to

a = 1;b = 2;

Installation

Add this line to your application's Gemfile:

gem 'groovy_oneliner'

And then execute:

$ bundle

Or install it yourself as:

$ gem install groovy_oneliner

Usage

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')

Contributing

  1. Fork it ( https://github.com/pedrocunha/groovy_oneliner/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request