Class: Braid::Operations::Proxy

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/braid/operations.rb

Overview

The command proxy is meant to encapsulate commands such as git, git-svn and svn, that work with subcommands.

Direct Known Subclasses

Git, GitSvn, Svn

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)



91
92
93
# File 'lib/braid/operations.rb', line 91

def method_missing(name, *args)
  invoke(name, *args)
end

Class Method Details

.commandObject

hax!



48
# File 'lib/braid/operations.rb', line 48

def self.command; name.split('::').last.downcase; end

Instance Method Details

#require_version(required) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/braid/operations.rb', line 55

def require_version(required)
  required = required.split(".")
  actual = version.split(".")

  actual.each_with_index do |actual_piece, idx|
    required_piece = required[idx]

    return true unless required_piece

    case (actual_piece <=> required_piece)
      when -1
        return false
      when 1
        return true
      when 0
        next
    end
  end

  return actual.length >= required.length
end

#require_version!(required) ⇒ Object



77
78
79
# File 'lib/braid/operations.rb', line 77

def require_version!(required)
  require_version(required) || raise(VersionTooLow.new(self.class.command, version, required))
end

#versionObject



50
51
52
53
# File 'lib/braid/operations.rb', line 50

def version
  status, out, err = exec!("#{self.class.command} --version")
  out.sub(/^.* version/, "").strip
end