Class: ActionController::UrlEncodedPairParser

Inherits:
StringScanner
  • Object
show all
Defined in:
lib/action_controller/request.rb

Overview

:nodoc:

Constant Summary collapse

KEY_REGEXP =
%r{([^\[\]=&]+)}
BRACKETED_KEY_REGEXP =
%r{\[([^\[\]=&]+)\]}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pairs = []) ⇒ UrlEncodedPairParser

Returns a new instance of UrlEncodedPairParser.



606
607
608
609
610
# File 'lib/action_controller/request.rb', line 606

def initialize(pairs = [])
  super('')
  @result = {}
  pairs.each { |key, value| parse(key, value) }
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



604
605
606
# File 'lib/action_controller/request.rb', line 604

def parent
  @parent
end

#resultObject (readonly)

Returns the value of attribute result.



604
605
606
# File 'lib/action_controller/request.rb', line 604

def result
  @result
end

#topObject (readonly)

Returns the value of attribute top.



604
605
606
# File 'lib/action_controller/request.rb', line 604

def top
  @top
end

Instance Method Details

#parse(key, value) ⇒ Object

Parse the query string



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
# File 'lib/action_controller/request.rb', line 616

def parse(key, value)
  self.string = key
  @top, @parent = result, nil

  # First scan the bare key
  key = scan(KEY_REGEXP) or return
  key = post_key_check(key)

  # Then scan as many nestings as present
  until eos?
    r = scan(BRACKETED_KEY_REGEXP) or return
    key = self[1]
    key = post_key_check(key)
  end

  bind(key, value)
end