Sha256: 0321f1dd3a6d7daf371aa9e383d23140ac6c74ab339560c1c0ab40c5fd83ff72

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

# encoding: UTF-8

require 'pathname'

module GoodData
  module Command
    class Runners
      def self.run_ruby_locally(brick_dir, options = {})
        pid = options[:project_id]
        fail 'You have to specify a project ID' if pid.nil?
        fail 'You have to specify directory of the brick run' if brick_dir.nil?
        fail 'You specified file as a birck run directory. You have to specify directory.' if File.exist?(brick_dir) && !File.directory?(brick_dir)

        params = options[:expanded_params] || {}

        client = GoodData.connect(options[:username], options[:password])
        sst = client.connection.sst_token
        pwd = Pathname.new(Dir.pwd)

        server_uri = URI(options[:server]) unless options[:server].nil?
        scheme = server_uri.nil? ? '' : server_uri.scheme
        hostname = server_uri.nil? ? '' : server_uri.host

        script_body = <<-script_body
        require 'fileutils'
        FileUtils::cd(\"#{pwd + brick_dir}\") do\
          require 'bundler/setup'

          $SCRIPT_PARAMS = {
            "GDC_SST" => \"#{sst}\",
            "GDC_PROJECT_ID" => \"#{pid}\",
            "GDC_PROTOCOL" => \"#{scheme}\",
            "GDC_HOSTNAME" => \"#{hostname}\",
            "GDC_LOGGER_FILE" => STDOUT,
            "GDC_ENV_LOCAL" => true
          }.merge(#{params})
          eval(File.read(\"./main.rb\"))
        end
        script_body

        Bundler.with_clean_env do
          system('ruby', '-e', script_body)
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gooddata-0.6.19 lib/gooddata/commands/runners.rb
gooddata-0.6.18 lib/gooddata/commands/runners.rb
gooddata-0.6.17 lib/gooddata/commands/runners.rb
gooddata-0.6.16 lib/gooddata/commands/runners.rb
gooddata-0.6.15 lib/gooddata/commands/runners.rb
gooddata-0.6.14 lib/gooddata/commands/runners.rb
gooddata-0.6.13 lib/gooddata/commands/runners.rb
gooddata-0.6.12 lib/gooddata/commands/runners.rb
gooddata-0.6.11 lib/gooddata/commands/runners.rb