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
- #http_post(*args) ⇒ 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
87 88 89 |
# File 'lib/github/command.rb', line 87 def current_user?(user) user == github_user || user == shell_user end |
#die(message) ⇒ Object
70 71 72 73 |
# File 'lib/github/command.rb', line 70 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
79 80 81 |
# File 'lib/github/command.rb', line 79 def github_token git("config --get github.token") end |
#github_user ⇒ Object
75 76 77 |
# File 'lib/github/command.rb', line 75 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 |
#http_post(*args) ⇒ Object
48 49 50 51 52 |
# File 'lib/github/command.rb', line 48 def http_post(*args) #require 'net/http' #need to work out a more appropriate place to put this GitHub.learn "Net::HTTP.post_form: " + args.inspect Net::HTTP.post_form(*args) 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
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/github/command.rb', line 54 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
66 67 68 |
# File 'lib/github/command.rb', line 66 def sh(*command) Shell.new(*command).run end |
#shell_user ⇒ Object
83 84 85 |
# File 'lib/github/command.rb', line 83 def shell_user ENV['USER'] end |