Class: JennCad::Commands::Run

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/jenncad/commands.rb

Direct Known Subclasses

Build, Observe

Instance Method Summary collapse

Instance Method Details

#check_executable(file) ⇒ Object



14
15
16
17
18
19
# File 'lib/jenncad/commands.rb', line 14

def check_executable(file)
  return true if File.exists?(file)
  # this is not too smart at the moment
  puts "cannot find executable #{file}"
  nil
end

#execute(file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/jenncad/commands.rb', line 34

def execute(file)
  print "refreshing..."
  r = system("./#{file}")
  case r
  when true
    $jenncad_profile.on_success(file)
  when false
    $jenncad_profile.on_error(file)
  end
end

#guess_executable(dir = Dir.pwd) ⇒ Object



10
11
12
# File 'lib/jenncad/commands.rb', line 10

def guess_executable(dir=Dir.pwd)
  dir.split("/").last.to_s + ".rb"
end

#observe(exec) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jenncad/commands.rb', line 21

def observe(exec)
  execute(exec)
  script = Observr::Script.new
  Dir.glob("**/**.rb").each do |file|
    script.watch(file) do
      execute(exec)
    end
  end
  contr = Observr::Controller.new(script, Observr.handler.new)
  puts "JennCad running, refreshing on file changes. Press ctrl+c to exit"
  contr.run
end