Class: Texas::Runner
- Inherits:
-
Object
- Object
- Texas::Runner
- Defined in:
- lib/texas/runner.rb
Instance Attribute Summary collapse
-
#task_instance ⇒ Object
readonly
Returns the value of attribute task_instance.
Instance Method Summary collapse
-
#display_error_message(ex) ⇒ Object
Display the error message that caused the exception.
- #extend_string_class ⇒ Object
- #fallback_task_class ⇒ Object
-
#initialize(force_options = nil) ⇒ Runner
constructor
A new instance of Runner.
- #load_local_libs ⇒ Object
- #run ⇒ Object
- #task_class ⇒ Object
Constructor Details
#initialize(force_options = nil) ⇒ Runner
Returns a new instance of Runner.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/texas/runner.rb', line 27 def initialize( = nil) @options = if .nil? Texas::OptionParser.new(ARGV).parse else opts = Texas::OptionParser.new([]).parse .each { |k, v| opts.send("#{k}=", v) } opts end extend_string_class Texas.verbose = @options.verbose Texas.warnings = @options.warnings load_local_libs if @options.load_local_libs @task_instance = task_class.new(@options) run end |
Instance Attribute Details
#task_instance ⇒ Object (readonly)
Returns the value of attribute task_instance.
25 26 27 |
# File 'lib/texas/runner.rb', line 25 def task_instance @task_instance end |
Instance Method Details
#display_error_message(ex) ⇒ Object
Display the error message that caused the exception.
44 45 46 47 48 49 50 51 52 |
# File 'lib/texas/runner.rb', line 44 def (ex) puts "#{@options.task} aborted!" puts ex. if @options.backtrace puts ex.backtrace else puts "(See full trace with --backtrace)" end end |
#extend_string_class ⇒ Object
54 55 56 57 |
# File 'lib/texas/runner.rb', line 54 def extend_string_class mod = @options.colors ? Term::ANSIColor : Term::NoColor String.send :include, mod end |
#fallback_task_class ⇒ Object
79 80 81 82 83 84 85 86 87 |
# File 'lib/texas/runner.rb', line 79 def fallback_task_class class_name = @options.task.to_s.split('_').map(&:capitalize).join begin eval("::Texas::Task::#{class_name}") rescue puts "Failed to fallback for Texas::Task::#{class_name}" exit end end |
#load_local_libs ⇒ Object
59 60 61 62 |
# File 'lib/texas/runner.rb', line 59 def load_local_libs init_file = File.join(@options.work_dir, "lib", "init.rb") require init_file if File.exist?(init_file) end |
#run ⇒ Object
64 65 66 67 68 69 |
# File 'lib/texas/runner.rb', line 64 def run @task_instance.run rescue Exception => ex ex exit 1 end |