class Dynosaur::Utils::RakeCommand
Constants
- PARSE_REGEX
Attributes
args[R]
task[R]
Public Class Methods
new(task:, args: [])
click to toggle source
# File lib/dynosaur/utils/rake_command.rb, line 26 def initialize(task:, args: []) @task = task @args = args end
parse(command)
click to toggle source
@param command [String] the command to parse @return [RakeCommand] an instance that represents the command being parsed @raise [ArgumentError] if the command is not a valid rake command
# 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)
click to toggle source
@param command [String] the command to test for validity @return [true|false] true iff the string is a valid rake command
# File lib/dynosaur/utils/rake_command.rb, line 11 def self.valid?(command) !(command =~ PARSE_REGEX).nil? end
Public Instance Methods
==(other)
click to toggle source
# File lib/dynosaur/utils/rake_command.rb, line 40 def ==(other) to_s == other.to_s end
to_s()
click to toggle source
@return [String] the full rake command, including arguments
# 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