Class: Texas::Runner
- Inherits:
-
Object
- Object
- Texas::Runner
- Includes:
- OutputHelper
- Defined in:
- lib/texas/runner.rb
Overview
An instance of Texas::Runner is used to run a build process.
Instance Attribute Summary collapse
-
#task_instance ⇒ Object
readonly
Returns the instance of the performed task.
Instance Method Summary collapse
-
#extend_string_class ⇒ Object
Extends String with Term::ANSIColor.
- #fallback_task_class ⇒ Object
-
#initialize(args = nil) ⇒ Runner
constructor
Initializes the Runner with an array or hash of options.
-
#load_local_libs ⇒ Object
Load lib/init.rb if present in current project.
- #options_from_args(args) ⇒ Object
- #run ⇒ Object
-
#task_class ⇒ Object
Returns the class for the given task.
Methods included from OutputHelper
Constructor Details
#initialize(args = nil) ⇒ Runner
Initializes the Runner with an array or hash of options.
Example:
Texas::Runner.new(%w(-w --no-color))
Texas::Runner.new(:warnings => true, :colors => false)
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/texas/runner.rb', line 18 def initialize(args = nil) = args extend_string_class Texas.verbose = .verbose Texas.warnings = .warnings load_local_libs if .load_local_libs verbose { TraceInfo.new(:starting, task_class, :magenta) } @task_instance = task_class.new() run end |
Instance Attribute Details
#task_instance ⇒ Object (readonly)
Returns the instance of the performed task. Normally a Texas::Build::Base derived object.
10 11 12 |
# File 'lib/texas/runner.rb', line 10 def task_instance @task_instance end |
Instance Method Details
#extend_string_class ⇒ Object
Extends String with Term::ANSIColor.
31 32 33 34 |
# File 'lib/texas/runner.rb', line 31 def extend_string_class String.send(:include, Term::ANSIColor) Term::ANSIColor::coloring = .colors end |
#fallback_task_class ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/texas/runner.rb', line 67 def fallback_task_class class_name = .task.to_s.split('_').map(&:capitalize).join begin eval("::Texas::Task::#{class_name}") rescue trace "Failed to fallback for Texas::Task::#{class_name}" exit end end |
#load_local_libs ⇒ Object
Load lib/init.rb if present in current project.
38 39 40 41 |
# File 'lib/texas/runner.rb', line 38 def load_local_libs init_file = File.join(.work_dir, "lib", "init.rb") load init_file if File.exist?(init_file) end |
#options_from_args(args) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/texas/runner.rb', line 43 def (args) if args.is_a?(Hash) opts = Texas::OptionParser.new([]).parse args.each { |k, v| opts.send("#{k}=", v) } opts else Texas::OptionParser.new(args).parse end end |
#run ⇒ Object
53 54 55 |
# File 'lib/texas/runner.rb', line 53 def run Build.run_with_nice_errors(@task_instance) { exit 1 } end |
#task_class ⇒ Object
Returns the class for the given task.
59 60 61 62 63 64 65 |
# File 'lib/texas/runner.rb', line 59 def task_class map = { :build => Build::Final, :dry => Build::Dry, } map[.task] || fallback_task_class end |