Class: ActionController::Routing::DynamicSegment
Overview
Instance Attribute Summary collapse
Attributes inherited from Segment
#is_optional
Instance Method Summary
collapse
Methods inherited from Segment
#all_optionals_available_condition, #continue_string_structure, #interpolation_statement
Constructor Details
#initialize(key = nil, options = {}) ⇒ DynamicSegment
Returns a new instance of DynamicSegment.
645
646
647
648
649
650
|
# File 'lib/action_controller/routing.rb', line 645
def initialize(key = nil, options = {})
super()
self.key = key
self.default = options[:default] if options.key? :default
self.is_optional = true if options[:optional] || options.key?(:default)
end
|
Instance Attribute Details
Returns the value of attribute default.
643
644
645
|
# File 'lib/action_controller/routing.rb', line 643
def default
@default
end
|
Returns the value of attribute key.
643
644
645
|
# File 'lib/action_controller/routing.rb', line 643
def key
@key
end
|
Returns the value of attribute regexp.
643
644
645
|
# File 'lib/action_controller/routing.rb', line 643
def regexp
@regexp
end
|
Instance Method Details
#build_pattern(pattern) ⇒ Object
711
712
713
714
715
716
|
# File 'lib/action_controller/routing.rb', line 711
def build_pattern(pattern)
chunk = regexp_chunk
chunk = "(#{chunk})" if Regexp.new(chunk).number_of_captures == 0
pattern = "#{chunk}#{pattern}"
optional? ? Regexp.optionalize(pattern) : pattern
end
|
#expiry_statement ⇒ Object
675
676
677
|
# File 'lib/action_controller/routing.rb', line 675
def expiry_statement
"expired, hash = true, options if !expired && expire_on[:#{key}]"
end
|
661
662
663
|
# File 'lib/action_controller/routing.rb', line 661
def
"#{local_name} = hash[:#{key}] && hash[:#{key}].to_param #{"|| #{default.inspect}" if default}"
end
|
679
680
681
682
683
684
|
# File 'lib/action_controller/routing.rb', line 679
def
s =
vc = value_check
s << "\nreturn [nil,nil] unless #{vc}" if vc
s << "\n#{expiry_statement}"
end
|
#interpolation_chunk ⇒ Object
686
687
688
|
# File 'lib/action_controller/routing.rb', line 686
def interpolation_chunk
"\#{CGI.escape(#{local_name}.to_s)}"
end
|
#local_name ⇒ Object
The local variable name that the value of this segment will be extracted to.
657
658
659
|
# File 'lib/action_controller/routing.rb', line 657
def local_name
"#{key}_value"
end
|
717
718
719
720
721
722
|
# File 'lib/action_controller/routing.rb', line 717
def (next_capture)
hangon = (default ? "|| #{default.inspect}" : "if match[#{next_capture}]")
"params[:#{key}] = match[#{next_capture}] #{hangon}"
end
|
#optionality_implied? ⇒ Boolean
724
725
726
|
# File 'lib/action_controller/routing.rb', line 724
def optionality_implied?
[:action, :id].include? key
end
|
#regexp_chunk ⇒ Object
707
708
709
|
# File 'lib/action_controller/routing.rb', line 707
def regexp_chunk
regexp ? "(#{regexp.source})" : "([^#{Routing::SEPARATORS.join}]+)"
end
|
#string_structure(prior_segments) ⇒ Object
690
691
692
693
694
695
696
697
698
699
700
701
702
|
# File 'lib/action_controller/routing.rb', line 690
def string_structure(prior_segments)
if optional? "if #{local_name} == #{default.inspect}\n" +
continue_string_structure(prior_segments) +
"\nelse\n" + "#{interpolation_statement(prior_segments)}\nend"
else
interpolation_statement(prior_segments)
end
end
|
652
653
654
|
# File 'lib/action_controller/routing.rb', line 652
def to_s
":#{key}"
end
|
#value_check ⇒ Object
664
665
666
667
668
669
670
671
672
673
674
|
# File 'lib/action_controller/routing.rb', line 664
def value_check
if default "#{value_regexp.inspect} =~ #{local_name}" if regexp
elsif optional?
"#{local_name}.nil? || #{value_regexp.inspect} =~ #{local_name}" if regexp
else "#{local_name} #{"&& #{value_regexp.inspect} =~ #{local_name}" if regexp}"
end
end
|
#value_regexp ⇒ Object
704
705
706
|
# File 'lib/action_controller/routing.rb', line 704
def value_regexp
Regexp.new "\\A#{regexp.source}\\Z" if regexp
end
|