Sha256: c53f4dd6635c9d7f75236e3af85a79160f5d807c518811ca2b2b370fdd2be0e6

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

module GitHandler
  module GitCommand
    GIT_COMMAND = /^(git-upload-pack|git upload-pack|git-upload-archive|git upload-archive|git-receive-pack|git receive-pack) '(.*)'$/

    COMMANDS_READONLY = [
      'git-upload-pack',
      'git upload-pack',
      'git-upload-archive',
      'git upload-archive'
    ]
  
    COMMANDS_WRITE = [
      'git-receive-pack',
      'git receive-pack'
    ]

    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

      {
        :action => action,
        :repo   => repo,
        :read   => read_command?(action),
        :write  => write_command?(action)
      }
    end
    
    def valid_command?(cmd)
      cmd =~ GIT_COMMAND ? true : false
    end
    
    def read_command?(cmd)
      COMMANDS_READONLY.include?(cmd)
    end
    
    def write_command?(cmd)
      COMMANDS_WRITE.include?(cmd)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_handler-0.2.0 lib/git_handler/git_command.rb