123456789_123456789_123456789_123456789_123456789_

Class: Rails::Command::RunnerCommand

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base, Thor
Instance Chain:
Inherits: Rails::Command::Base
Defined in: railties/lib/rails/commands/runner/runner_command.rb

Class Attribute Summary

Base - Inherited

.bin, .bin?,
.engine?

Returns true when the app is a Rails engine.

.exit_on_failure?

Class Method Summary

Base - Inherited

.banner,
.base_name

Sets the base_name taking into account the current class namespace.

.command_name

Return command name without namespaces.

.default_command_root

Default file root to place extra files a command might need, placed one folder above the command file.

.desc

Tries to get the description from a USAGE file one folder above the command root.

.executable,
.hide_command!

Convenience method to hide this command from the available ones when running rails command.

.namespace

Convenience method to get the namespace from the class name.

.printing_commands,
.usage_path

Path to lookup a USAGE description in a file.

.create_command

Allow the command method to be called perform.

.namespaced_name, .resolve_path, .class_usage,
.help

Override Thor’s class-level help to also show the USAGE.

.inherited, .perform

Instance Attribute Summary

Instance Method Summary

Instance Method Details

#conditional_executor(enabled, **args, &block) (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/runner/runner_command.rb', line 68

def conditional_executor(enabled, **args, &block)
  if enabled
    Rails.application.executor.wrap(**args, &block)
  else
    yield
  end
end

#looks_like_a_file_path?(code_or_file) ⇒ Boolean (private)

[ GitHub ]

  
# File 'railties/lib/rails/commands/runner/runner_command.rb', line 76

def looks_like_a_file_path?(code_or_file)
  code_or_file.ends_with?(".rb")
end

#perform(code_or_file = nil, *command_argv)

[ GitHub ]

  
# File 'railties/lib/rails/commands/runner/runner_command.rb', line 24

def perform(code_or_file = nil, *command_argv)
  unless code_or_file
    help
    exit 1
  end

  boot_application!
  Rails.application.load_runner

  ARGV.replace(command_argv)

  wrap_with_executor = !options[:skip_executor]
  if code_or_file == "-"
    conditional_executor(wrap_with_executor, source: "application.runner.railties") do
      eval($stdin.read, TOPLEVEL_BINDING, "stdin")
    end
  elsif File.exist?(code_or_file)
    expanded_file_path = File.expand_path code_or_file
    $0 = expanded_file_path
    conditional_executor(wrap_with_executor, source: "application.runner.railties") do
      Kernel.load expanded_file_path
    end
  else
    begin
      conditional_executor(wrap_with_executor, source: "application.runner.railties") do
        eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)
      end
    rescue SyntaxError, NameError => e
      if looks_like_a_file_path?(code_or_file)
        error "The file #{code_or_file} could not be found, please check and try again."
        error "Run '#{self.class.executable} -h' for help."
      else
        error "Please specify a valid ruby command or the path of a script to run."
        error "Run '#{self.class.executable} -h' for help."
        error ""
        error e
      end

      exit 1
    end
  end
end