Class: GitHub::Command

Inherits:
Object show all
Includes:
FileUtils
Defined in:
lib/github/command.rb

Direct Known Subclasses

GitCommand

Defined Under Namespace

Classes: Shell

Instance Method Summary collapse

Constructor Details

#initialize(block) ⇒ Command

Returns a new instance of Command.



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

def initialize(block)
  (class << self;self end).send :define_method, :command, &block
end

Instance Method Details

#call(*args) ⇒ Object



22
23
24
25
26
# File 'lib/github/command.rb', line 22

def call(*args)
  arity = method(:command).arity
  args << nil while args.size < arity
  send :command, *args
end

#current_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/github/command.rb', line 81

def current_user?(user)
  user == github_user || user == shell_user
end

#die(message) ⇒ Object



64
65
66
67
# File 'lib/github/command.rb', line 64

def die(message)
  puts "=> #{message}"
  exit!
end

#git(command) ⇒ Object



40
41
42
# File 'lib/github/command.rb', line 40

def git(command)
  run :sh, command
end

#git_exec(command) ⇒ Object



44
45
46
# File 'lib/github/command.rb', line 44

def git_exec(command)
  run :exec, command
end

#github_tokenObject



73
74
75
# File 'lib/github/command.rb', line 73

def github_token
  git("config --get github.token")
end

#github_userObject



69
70
71
# File 'lib/github/command.rb', line 69

def github_user
  git("config --get github.user")
end

#helperObject



28
29
30
# File 'lib/github/command.rb', line 28

def helper
  @helper ||= Helper.new
end

#optionsObject



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

def options
  GitHub.options
end

#pgit(*command) ⇒ Object



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

def pgit(*command)
  puts git(*command)
end

#run(method, command) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/github/command.rb', line 48

def run(method, command)
  if command.is_a? Array
    command = [ 'git', command ].flatten
    GitHub.learn command.join(' ')
  else
    command = 'git ' + command
    GitHub.learn command
  end

  send method, *command
end

#sh(*command) ⇒ Object



60
61
62
# File 'lib/github/command.rb', line 60

def sh(*command)
  Shell.new(*command).run
end

#shell_userObject



77
78
79
# File 'lib/github/command.rb', line 77

def shell_user
  ENV['USER']
end