Class: GitAuth::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gitauth/command.rb

Constant Summary collapse

READ_COMMANDS =

Standard Commands

["git-upload-pack", "git upload-pack"]
WRITE_COMMANDS =
["git-receive-pack", "git receive-pack"]
PATH_REGEXP =
/^'([\w\_\-\~\.\+\/]+\/)?([\w\_\-\.\+]+(\.git)?)'$/i.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Command

Returns a new instance of Command.



40
41
42
43
44
45
46
# File 'lib/gitauth/command.rb', line 40

def initialize(command)
  @command     = command
  @verb        = nil
  @argument    = nil
  @path        = nil
  @bad_command = true
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



38
39
40
# File 'lib/gitauth/command.rb', line 38

def command
  @command
end

#pathObject (readonly)

Returns the value of attribute path.



38
39
40
# File 'lib/gitauth/command.rb', line 38

def path
  @path
end

#verbObject (readonly)

Returns the value of attribute verb.



38
39
40
# File 'lib/gitauth/command.rb', line 38

def verb
  @verb
end

Class Method Details

.parse(command) ⇒ Object



81
82
83
84
85
# File 'lib/gitauth/command.rb', line 81

def self.parse(command)
  command = self.new(command)
  command.process
  command
end

Instance Method Details

#bad?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/gitauth/command.rb', line 48

def bad?
  @bad_command
end

#processObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gitauth/command.rb', line 60

def process
  return if @command.include?("\n") || @command !~ /^git[ \-]/i
  @verb, @argument = split_command
  return if @argument.nil? || @argument.is_a?(Array) 
  # Check if it's read / write
  if READ_COMMANDS.include?(@verb)
    @verb_type = :read
  elsif WRITE_COMMANDS.include?(@verb)
    @verb_type = :write
  else
    return
  end
  if PATH_REGEXP =~ @argument
    @path = $2
    return unless @path
  else
    return
  end
  @bad_command = false
end

#read?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gitauth/command.rb', line 56

def read?
  !bad? && !write?
end

#write?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gitauth/command.rb', line 52

def write?
  !bad? && @verb_type == :write
end