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
Extends String with Term::ANSIColor if options demand it.
- #fallback_task_class ⇒ Object
-
#initialize(force_options = nil) ⇒ Runner
constructor
A new instance of Runner.
-
#load_local_libs ⇒ Object
Load lib/init.rb if present in current project.
- #run ⇒ Object
-
#task_class ⇒ Object
Returns the class for the given task.
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) = 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 = .verbose Texas.warnings = .warnings load_local_libs if .load_local_libs @task_instance = task_class.new() 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.
45 46 47 48 49 50 51 52 53 |
# File 'lib/texas/runner.rb', line 45 def (ex) puts "#{@options.task} aborted!" puts ex. if .backtrace puts ex.backtrace else puts "(See full trace with --backtrace)" end end |
#extend_string_class ⇒ Object
Extends String with Term::ANSIColor if options demand it.
57 58 59 60 |
# File 'lib/texas/runner.rb', line 57 def extend_string_class mod = .colors ? Term::ANSIColor : Term::NoColor String.send :include, mod end |
#fallback_task_class ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/texas/runner.rb', line 86 def fallback_task_class class_name = .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
Load lib/init.rb if present in current project.
64 65 66 67 |
# File 'lib/texas/runner.rb', line 64 def load_local_libs init_file = File.join(.work_dir, "lib", "init.rb") require init_file if File.exist?(init_file) end |
#run ⇒ Object
69 70 71 72 73 74 |
# File 'lib/texas/runner.rb', line 69 def run @task_instance.run rescue Exception => ex ex exit 1 end |
#task_class ⇒ Object
Returns the class for the given task.
78 79 80 81 82 83 84 |
# File 'lib/texas/runner.rb', line 78 def task_class map = { :build => Build::Final, :dry => Build::Dry, } map[.task] || fallback_task_class end |