class GitValidation::Task
Task
implements the task for the git-validation tool.
Attributes
from[RW]
quiet[RW]
run[RW]
Public Class Methods
new(name = :"git-validation", *args) { |*[self, task_args].slice(0, arity)| ... }
click to toggle source
# File lib/git_validation/task.rb, line 33 def initialize(name = :"git-validation", *args, &block) set_ivars desc "Run git-validation" unless ::Rake.application.last_description task(name, *args) do |_, task_args| abort("The git-validation command could not be found") unless git_validation? yield(*[self, task_args].slice(0, block.arity)) if block_given? abort("Bad type for 'from' option") unless @from.is_a?(String) execute! end end
Protected Instance Methods
execute!()
click to toggle source
Execute the actual shell command with all the needed flags.
# File lib/git_validation/task.rb, line 58 def execute! sh("git-validation", *range_flag, *run_flag, *quiet_flag) end
git_validation?()
click to toggle source
Returns true if `git-validation` could be found in the filesystem and it's executable.
# File lib/git_validation/task.rb, line 105 def git_validation? ENV["PATH"].split(File::PATH_SEPARATOR).each do |path| bin = File.join(path, "git-validation") return true if File.executable?(bin) && !File.directory?(bin) end nil end
present?(str)
click to toggle source
Returns true if the given string is not blank (nil nor empty).
# File lib/git_validation/task.rb, line 99 def present?(str) !str.nil? && str != "" end
quiet_flag()
click to toggle source
Returns an array containing the `-q` flag if it was specified.
# File lib/git_validation/task.rb, line 92 def quiet_flag return ["-q"] if @quiet [] end
range_flag()
click to toggle source
Returns an array containing the arguments to be passed to the git-validation command for the '-range' flag (where '-range') is already included.
# File lib/git_validation/task.rb, line 65 def range_flag return ["-range", ENV["TRAVIS_COMMIT_RANGE"]] if present?(ENV["TRAVIS_COMMIT_RANGE"]) return [] unless present?(@from) unless @from.is_a?(String) puts "Given 'from' argument is not a string. Ignoring..." return [] end ["-range", "#{@from}..HEAD"] end
run_flag()
click to toggle source
Returns an array containing the arguments to be passed to the git-validation command for the '-run' flag (where '-run') is already included.
# File lib/git_validation/task.rb, line 80 def run_flag return [] unless present?(@run) unless @run.is_a?(String) puts "Given 'run' argument is not a string. Ignoring..." return [] end ["-run", @run] end
set_ivars()
click to toggle source
Initialize the ivars that are relevant to us.
# File lib/git_validation/task.rb, line 51 def set_ivars @from = nil @run = nil @quiet = false end