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.map {|m| m.intern }
end

#debug(msg) ⇒ Object



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

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

#guess_ownerObject



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

def guess_owner
  output = run("git config --get remote.origin.url")
  output[/github.com[:\/](\w+)/, 1] || raise_if_no_owner(output)
end

#invoke(command, *args) ⇒ Object



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

def invoke(command, *args)
  command = command.intern
  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

#raise_if_no_owner(output) ⇒ Object

Raises:

  • (ArgumentError)


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

def raise_if_no_owner(output)
  raise(ArgumentError, "Could not determine owner from git remote url: #{output}")
end

#run(cmd) ⇒ Object



50
51
52
# File 'lib/runcoderun.rb', line 50

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

#uiObject



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

def ui
  $stdout
end