Sha256: 13d52bc85ac274ff736e619bd2a3a2e5936625051d78efa1765fd531348a24a7
Contents?: true
Size: 1.68 KB
Versions: 1
Compression:
Stored size: 1.68 KB
Contents
module GitHandler module GitCommand GIT_COMMAND = /\A(git[-|\s]upload-pack|git[-|\s]upload-archive|git[-|\s]receive-pack) '(.*)'\z/ GIT_REPO = /\A[a-z\d\-\_\.]{1,128}.git?\z/i COMMANDS_READONLY = [ 'git-upload-pack', 'git upload-pack', 'git-upload-archive', 'git upload-archive' ] COMMANDS_WRITE = [ 'git-receive-pack', 'git receive-pack' ] # Parse original git command # @param [String] cmd git command string # @return [Hash] parse result def parse_command(cmd) unless valid_command?(cmd) raise ParseError, "Invalid command: #{cmd}" end match = cmd.scan(GIT_COMMAND).flatten action = match.first repo = match.last unless valid_repository?(repo) raise ParseError, "Invalid repository: #{repo}" end { :action => action, :repo => repo, :read => read_command?(action), :write => write_command?(action) } end # Check if valid git command # @param [String] str command string # @return [Boolean] def valid_command?(str) str =~ GIT_COMMAND ? true : false end # Check if read command # @param [String] str command string # @return [Boolean] def read_command?(str) COMMANDS_READONLY.include?(str) end # Check if write command # @param [String] str command string # @return [Boolean] def write_command?(str) COMMANDS_WRITE.include?(str) end # Check if repository name is valid # @param [String] name repository name # @return [Boolean] def valid_repository?(name) name =~ GIT_REPO ? true : false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
git_handler-0.2.2 | lib/git_handler/git_command.rb |