Class: Cassie::Tasks::TaskRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/cassie/tasks/task_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ TaskRunner



9
10
11
12
13
14
# File 'lib/cassie/tasks/task_runner.rb', line 9

def initialize(args)
  @args = args
  @command = nil
  @command = args.delete_at(0) if args.first =~ /\A[^-]/
  @options = {}
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



5
6
7
# File 'lib/cassie/tasks/task_runner.rb', line 5

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/cassie/tasks/task_runner.rb', line 6

def command
  @command
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cassie/tasks/task_runner.rb', line 7

def options
  @options
end

#raw_argsObject (readonly)

Returns the value of attribute raw_args.



4
5
6
# File 'lib/cassie/tasks/task_runner.rb', line 4

def raw_args
  @raw_args
end

Instance Method Details

#display_infoObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cassie/tasks/task_runner.rb', line 34

def display_info
  case
  when command && !task
    puts "'#{command}' is not a supported command.\n\n"
    print_documentation
  when options[:show_help]
    print_documentation
  when options[:show_version]
    puts Cassie::VERSION
  else
    print_documentation
  end
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cassie/tasks/task_runner.rb', line 16

def run
  build_options
  Cassie.logger.level = ::Logger::WARN unless options[:debug]
  Cassie.env = options[:environment] if options[:environment]
  Cassie::Tasks::IO.trace! if options[:trace]

  run_command || display_info
rescue OptionParser::InvalidOption => e
  puts("#{e.message}\n\n")
  display_info
end

#taskObject



29
30
31
32
# File 'lib/cassie/tasks/task_runner.rb', line 29

def task
  task_name = "cassie:#{command}"
  Rake::Task[task_name] if Rake::Task.task_defined?(task_name)
end