Class: Texas::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/texas/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(force_options = nil)
  @options = if force_options.nil?
    Texas::OptionParser.new(ARGV).parse
  else
    opts = Texas::OptionParser.new([]).parse
    force_options.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_instanceObject (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 display_error_message(ex)
  puts "#{@options.task} aborted!"
  puts ex.message
  if @options.backtrace
    puts ex.backtrace
  else
    puts "(See full trace with --backtrace)"
  end
end

#extend_string_classObject



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_classObject



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_libsObject



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

#runObject



64
65
66
67
68
69
# File 'lib/texas/runner.rb', line 64

def run
  @task_instance.run
rescue Exception => ex
  display_error_message ex
  exit 1
end

#task_classObject



71
72
73
74
75
76
77
# File 'lib/texas/runner.rb', line 71

def task_class
  map = {
    :build      => Build::Final,
    :dry        => Build::Dry,
  }
  map[@options.task] || fallback_task_class
end