Class: CommandMapper::Gen::Task
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- CommandMapper::Gen::Task
- Defined in:
- lib/command_mapper/gen/task.rb
Overview
Defines a command_mapper:gen
task which automatically generates a
command class file.
require 'command_mapper/gen/task'
CommandMapper::Gen::Task.new('grep','lib/path/to/grep.rb')
$ rake command_mapper:gen
Instance Attribute Summary collapse
-
#command_name ⇒ String
The command name or path to the command.
-
#output ⇒ String
The output file path.
-
#parser ⇒ :help, ...
The parser to invoke.
Instance Method Summary collapse
-
#define ⇒ Object
Defines the
command_mapper:gen
task and output file's task. -
#generate ⇒ Object
Generates the #output file.
-
#initialize(command_name, output, parser: nil) {|task| ... } ⇒ Task
constructor
Initializes the task.
Constructor Details
#initialize(command_name, output, parser: nil) {|task| ... } ⇒ Task
Initializes the task.
50 51 52 53 54 55 56 57 58 |
# File 'lib/command_mapper/gen/task.rb', line 50 def initialize(command_name,output, parser: nil) @command_name = command_name @output = output @parser = parser yield self if block_given? define end |
Instance Attribute Details
#command_name ⇒ String
The command name or path to the command.
19 20 21 |
# File 'lib/command_mapper/gen/task.rb', line 19 def command_name @command_name end |
#output ⇒ String
The output file path.
24 25 26 |
# File 'lib/command_mapper/gen/task.rb', line 24 def output @output end |
#parser ⇒ :help, ...
The parser to invoke.
29 30 31 |
# File 'lib/command_mapper/gen/task.rb', line 29 def parser @parser end |
Instance Method Details
#define ⇒ Object
Defines the command_mapper:gen
task and output file's task.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/command_mapper/gen/task.rb', line 63 def define output_dir = File.dirname(@output) directory(output_dir) file(@output => output_dir) do generate end desc "Generates the #{@output} file" task 'command_mapper:gen' => @output end |
#generate ⇒ Object
Generates the #output file.
78 79 80 81 82 83 84 85 86 |
# File 'lib/command_mapper/gen/task.rb', line 78 def generate args = ["--output", @output] if @parser args << '--parser' << @parser.to_s end sh "command_mapper-gen", *args, @command_name end |