Class: GitAuth::Command
- Inherits:
-
Object
- Object
- GitAuth::Command
- 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
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
- #bad? ⇒ Boolean
-
#initialize(command) ⇒ Command
constructor
A new instance of Command.
- #process ⇒ Object
- #read? ⇒ Boolean
- #write? ⇒ Boolean
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
#command ⇒ Object (readonly)
Returns the value of attribute command.
38 39 40 |
# File 'lib/gitauth/command.rb', line 38 def command @command end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
38 39 40 |
# File 'lib/gitauth/command.rb', line 38 def path @path end |
#verb ⇒ Object (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
48 49 50 |
# File 'lib/gitauth/command.rb', line 48 def bad? @bad_command end |
#process ⇒ Object
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
56 57 58 |
# File 'lib/gitauth/command.rb', line 56 def read? !bad? && !write? end |
#write? ⇒ Boolean
52 53 54 |
# File 'lib/gitauth/command.rb', line 52 def write? !bad? && @verb_type == :write end |