jazzido / mondrian-rest

A REST interface for Mondrian ROLAP server
MIT License
32 stars 8 forks source link

Please make it easy to set the olap connection #22

Open kwerle opened 7 years ago

kwerle commented 7 years ago

The backtrace when you don't set the connection at all:

NoMethodError (undefined method `[]' for nil:NilClass):
  mondrian-olap (0.8.0) lib/mondrian/olap/connection.rb:15:in `initialize'
  mondrian-rest-0.7.0 (java) lib/mondrian_rest/api_helpers.rb:13:in `olap'
  mondrian-rest-0.7.0 (java) lib/mondrian_rest/api.rb:70:in `block in GET cubes  /'

Setting the olap connection in the env is possible, but kind of a hack. It would be exceptionally nice if there were some class or something where you could set the connection "globally" so that the library could grab ahold of it.

# If you want to set the connection, just call ConnectionClass.connection = my_connection
# Otherwise it will read env['mondrian-olap.params']
class ConnectionClass
  @@connection = nil
  def self.connection=(connection); @@connection = connection; end
  def self.connection
    return @@connection ||= Mondrian::OLAP::Connection.new(env['mondrian-olap.params'])
  end
end
jazzido commented 7 years ago

Looks good, can you send a PR? Thanks!