Class: Dynosaur::Utils::RakeCommand
- Inherits:
-
Object
- Object
- Dynosaur::Utils::RakeCommand
- Defined in:
- lib/dynosaur/utils/rake_command.rb
Constant Summary collapse
- PARSE_REGEX =
/\brake\s+([\w:]+)(\[.*\])?/
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
Class Method Summary collapse
-
.parse(command) ⇒ RakeCommand
An instance that represents the command being parsed.
-
.valid?(command) ⇒ true|false
True iff the string is a valid rake command.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(task:, args: []) ⇒ RakeCommand
constructor
A new instance of RakeCommand.
-
#to_s ⇒ String
The full rake command, including arguments.
Constructor Details
#initialize(task:, args: []) ⇒ RakeCommand
Returns a new instance of RakeCommand.
26 27 28 29 |
# File 'lib/dynosaur/utils/rake_command.rb', line 26 def initialize(task:, args: []) @task = task @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/dynosaur/utils/rake_command.rb', line 7 def args @args end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
7 8 9 |
# File 'lib/dynosaur/utils/rake_command.rb', line 7 def task @task end |
Class Method Details
.parse(command) ⇒ RakeCommand
Returns an instance that represents the command being parsed.
18 19 20 21 22 23 24 |
# File 'lib/dynosaur/utils/rake_command.rb', line 18 def self.parse(command) match = command.match(PARSE_REGEX) raise ArgumentError, %Q(Invalid rake command: "#{command}") unless match task = match[1] args = match[2] ? match[2].tr('[]', '').split(',') : [] new(task: task, args: args) end |
.valid?(command) ⇒ true|false
Returns true iff the string is a valid rake command.
11 12 13 |
# File 'lib/dynosaur/utils/rake_command.rb', line 11 def self.valid?(command) !(command =~ PARSE_REGEX).nil? end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 |
# File 'lib/dynosaur/utils/rake_command.rb', line 40 def ==(other) to_s == other.to_s end |
#to_s ⇒ String
Returns the full rake command, including arguments.
32 33 34 35 36 37 38 |
# File 'lib/dynosaur/utils/rake_command.rb', line 32 def to_s formatted_args = args.map do |arg| arg.is_a?(String) ? arg.shellescape : arg end.join(',') task_with_args = args.empty? ? task : "#{task}[#{formatted_args}]" "rake #{task_with_args} --trace" end |