Class: ORS::Commands::Runner

Inherits:
Base
  • Object
show all
Defined in:
lib/ors/commands/runner.rb

Instance Method Summary collapse

Methods inherited from Base

#help, #help_options

Methods included from Base::ClassMethods

#run, #run_without_setup

Methods included from Helpers

#build_command, #execute_command, #execute_in_parallel, #fatal, #info

Methods included from Helpers::CommandHelpers

#bundle_install, #restart_server, #run_migrations, #setup_repo, #setup_ruby, #start_server, #stop_server, #update_code

Methods included from Helpers::PrepareHelpers

#prepare_environment, #prepare_environment_with_rvm, #prepare_initial_environment

Methods included from Helpers::ParseHelpers

#parse_remote_and_or_branch

Instance Method Details

#descriptionObject



28
29
30
31
32
33
34
# File 'lib/ors/commands/runner.rb', line 28

def description
  <<-END
Runs rails runner returning the result on STDOUT.
The ruby code will be transmitted within several nested quotes:  '"\"ruby code here\""'
Keep that in mind if you need to use quotes.
  END
end

#executeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ors/commands/runner.rb', line 8

def execute
  # need code to run
  fatal "ERROR: Missing 'ruby code'." if @code.nil?

  # get results
  results = execute_command(ORS.config[:console_server],
                            prepare_environment,
                            %(if [ -f script/rails ]; then bundle exec rails runner -e #{ORS.config[:environment]} \\"#{@code}\\"; else ./script/runner -e #{ORS.config[:environment]} \\"#{@code}\\"; fi),
                            :capture => true, :quiet_ssh => true)

  # The central_logger gem spits this out
  results.sub!(/\AUsing BufferedLogger due to exception: .*?\n/, '')

  puts results
end

#setupObject



4
5
6
# File 'lib/ors/commands/runner.rb', line 4

def setup
  @code = ORS.config[:args].shift
end

#usageObject



24
25
26
# File 'lib/ors/commands/runner.rb', line 24

def usage
  "./ors runner 'ruby code here' [options]"
end