Class: GoodData::Command::Runners

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/commands/runners.rb

Class Method Summary collapse

Class Method Details

.run_ruby_locally(brick_dir, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gooddata/commands/runners.rb', line 12

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 = "  require 'fileutils'\n  FileUtils::cd(\\\"\#{pwd + brick_dir}\\\") do\\\n\n    $SCRIPT_PARAMS = {\n      \"GDC_SST\" => \\\"\#{sst}\\\",\n      \"GDC_PROJECT_ID\" => \\\"\#{pid}\\\",\n      \"GDC_PROTOCOL\" => \\\"\#{scheme}\\\",\n      \"GDC_HOSTNAME\" => \\\"\#{hostname}\\\",\n      \"GDC_LOGGER_FILE\" => STDOUT,\n      \"GDC_ENV_LOCAL\" => true\n    }.merge(\#{params})\n    require './main.rb'\n  end\n  script_body\n  system('ruby', '-e', script_body)\nend\n"