Class: GitHub::Command
- Includes:
- FileUtils
- Defined in:
- lib/github/command.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Shell
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #current_user?(user) ⇒ Boolean
- #die(message) ⇒ Object
- #git(command) ⇒ Object
- #git_exec(command) ⇒ Object
- #github_token ⇒ Object
- #github_user ⇒ Object
- #helper ⇒ Object
-
#initialize(block) ⇒ Command
constructor
A new instance of Command.
- #options ⇒ Object
- #pgit(*command) ⇒ Object
- #run(method, command) ⇒ Object
- #sh(*command) ⇒ Object
- #shell_user ⇒ Object
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
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() puts "=> #{}" 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_token ⇒ Object
73 74 75 |
# File 'lib/github/command.rb', line 73 def github_token git("config --get github.token") end |
#github_user ⇒ Object
69 70 71 |
# File 'lib/github/command.rb', line 69 def github_user git("config --get github.user") end |
#helper ⇒ Object
28 29 30 |
# File 'lib/github/command.rb', line 28 def helper @helper ||= Helper.new 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_user ⇒ Object
77 78 79 |
# File 'lib/github/command.rb', line 77 def shell_user ENV['USER'] end |