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, that work with subcommands.

Direct Known Subclasses

Git

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)



93
94
95
96
97
98
# File 'lib/braid/operations.rb', line 93

def method_missing(name, *args)
  # We have to use this rather than `T.unsafe` because `invoke` is
  # private.  See https://sorbet.org/docs/type-assertions#tbind.
  T.bind(self, T.untyped)
  invoke(name, *args)
end

Class Method Details

.commandObject



60
61
62
# File 'lib/braid/operations.rb', line 60

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

Instance Method Details

#require_version(required) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/braid/operations.rb', line 70

def require_version(required)
  # Gem::Version is intended for Ruby gem versions, but various web sites
  # suggest it as a convenient way of comparing version strings in
  # general.  None of the fine points of its semantics compared to those
  # of Git version numbers seem likely to cause a problem for Braid.
  Gem::Version.new(version) >= Gem::Version.new(required)
end

#require_version!(required) ⇒ Object



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

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

#versionObject

hax!



65
66
67
68
# File 'lib/braid/operations.rb', line 65

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