class Fixman::RawTask

Public Class Methods

new(params) click to toggle source
# File lib/fixman/raw_task.rb, line 8
def initialize params
  # Common to commands, cleanup, condition
  @name = params[:name]
  @target_placeholder = params[:target_placeholder]

  # Command to execute and check exit status
  @command = params[:command]
  @variables = params[:variables] || []

  # Condition to run the task
  @condition = params[:condition]

  # Clean up
  @cleanup = params[:cleanup]
end

Public Instance Methods

refine() click to toggle source
# File lib/fixman/raw_task.rb, line 24
def refine
  condition_proc = refine_condition
  cleanup_proc = refine_cleanup
  command_procs = refine_command

  command_procs.map do |command_proc|
    Task.new @name, condition_proc, command_proc, cleanup_proc
  end
end

Private Instance Methods

refine_command() click to toggle source
# File lib/fixman/raw_task.rb, line 60
def refine_command
  actions = substitute_variables

  actions.map do |action|
    shell_to_proc action, @command[:exit_status]
  end
end
shell_to_proc(shell_command, exit_status) click to toggle source
# File lib/fixman/raw_task.rb, line 85
def shell_to_proc(shell_command, exit_status)
  proc do |target|
    final_command_str =
    if target
      shell_command.gsub(@target_placeholder, target.to_s)
    else
      shell_command
    end

    final_command_str << ' &> /dev/null'

    system(final_command_str)
    if exit_status
      $CHILD_STATUS.exitstatus == exit_status
    end
  end
end
substitute_variables() click to toggle source
# File lib/fixman/raw_task.rb, line 68
def substitute_variables
  actions = [@command[:action]]

  @variables.each do |variable|
    key_regexp = Regexp.new variable[:key]
    actions.map! do |action|
      if key_regexp =~ action
        variable[:values].map { |value| action.gsub(variable[:key], value) }
      else
        action
      end
    end.flatten!
  end

  actions
end