Class: GitPm::Git
- Inherits:
-
Object
- Object
- GitPm::Git
- Defined in:
- lib/git_pm/git.rb
Instance Method Summary collapse
-
#initialize ⇒ Git
constructor
A new instance of Git.
- #method_missing(cmd, opts = {}, *args) ⇒ Object
-
#set_options!(options) ⇒ Object
git-dir, –exec-path, –paginate, –bare.
Constructor Details
#initialize ⇒ Git
Returns a new instance of Git.
7 8 9 10 |
# File 'lib/git_pm/git.rb', line 7 def initialize @binary = "git" @preopt_args = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(cmd, opts = {}, *args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git_pm/git.rb', line 17 def method_missing(cmd, opts = {}, *args) opt_args = (opts) ext_args = args.map { |a| if not a.to_s.empty? then (a == '--' or a =~ /^\s*\|/) ? a : "'#{shell_escape(a)}'" end } call = "#{@binary} #{@preopt_args} #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}" $stderr.puts call if $DEBUG stdin, stdout, stderr = Open3.popen3(call) if block_given? yield stdout, stderr end lines = stdout.readlines stdout.close stderr.close stdin.close lines end |
Instance Method Details
#set_options!(options) ⇒ Object
git-dir, –exec-path, –paginate, –bare
13 14 15 |
# File 'lib/git_pm/git.rb', line 13 def () @preopt_args = () end |