Class: Consist::Commands::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/consist/commands/check.rb

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Check

Returns a new instance of Check.



6
7
8
# File 'lib/consist/commands/check.rb', line 6

def initialize(command)
  @command = command
end

Instance Method Details

#perform!(executor) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/consist/commands/check.rb', line 10

def perform!(executor)
  status = @command[:status]

  flag, val = if @command.has_key?(:path) && !@command[:path].nil?
    ["d", @command[:path]]
  else
    ["f", @command[:file]]
  end

  exists = executor.test("[ -#{flag} #{val} ]")

  if status == :exist && !exists
    @command[:block].call
  elsif status == :nonexistant && !exists
    @command[:block].call
  else
    tense = if status == :exist
      "should"
    elsif status == :nonexistant
      "shoudlnt"
    end
    puts "Checking path `#{status}` - `#{val}` - #{exists ? "exists" : "doesn't exist"} and #{tense} - skipping"
  end
end