Module: RunCodeRun

Extended by:
RunCodeRun
Included in:
RunCodeRun
Defined in:
lib/runcoderun.rb,
lib/commands/commands.rb

Defined Under Namespace

Modules: Commands

Instance Method Summary collapse

Instance Method Details

#activate(args) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/runcoderun.rb', line 10

def activate(args)
  if args.empty? || args.nil?
    invoke("help")
  else
    invoke(args.shift, *args)
  end
end

#all_commandsObject



18
19
20
# File 'lib/runcoderun.rb', line 18

def all_commands
  Commands.public_instance_methods(true).sort
end

#debug(msg) ⇒ Object



36
37
38
# File 'lib/runcoderun.rb', line 36

def debug(msg)
  puts(msg) if $DEBUG
end

#guess_ownerObject



40
41
42
43
# File 'lib/runcoderun.rb', line 40

def guess_owner
  output = run("git remote -v")
  output.match(%r{github.com[:/](\w+)})[1]
end

#invoke(command, *args) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/runcoderun.rb', line 22

def invoke(command, *args)
  debug "Invoking command: #{command}, args: #{args.inspect}"
  if all_commands.include?(command)
    Commands.send(command, *args)
  else
    ui.puts %[The command '#{command}' does not exist; currently supported commands are '#{all_commands.join(", ")}']
    abort
  end
end

#run(cmd) ⇒ Object



45
46
47
# File 'lib/runcoderun.rb', line 45

def run(cmd)
  `#{cmd}`
end

#uiObject



32
33
34
# File 'lib/runcoderun.rb', line 32

def ui
  $stdout
end