Class: ActionController::Routing::Segment

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

Overview

:nodoc:

Direct Known Subclasses

DynamicSegment, StaticSegment

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSegment

Returns a new instance of Segment.



543
544
545
# File 'lib/action_controller/routing.rb', line 543

def initialize
  self.is_optional = false
end

Instance Attribute Details

#is_optionalObject Also known as: optional?

Returns the value of attribute is_optional.



540
541
542
# File 'lib/action_controller/routing.rb', line 540

def is_optional
  @is_optional
end

Instance Method Details

#all_optionals_available_condition(prior_segments) ⇒ Object

Return an if condition that is true if all the prior segments can be generated. If there are no optional segments before this one, then nil is returned.



574
575
576
577
# File 'lib/action_controller/routing.rb', line 574

def all_optionals_available_condition(prior_segments)
  optional_locals = prior_segments.collect { |s| s.local_name if s.optional? && s.respond_to?(:local_name) }.compact
  optional_locals.empty? ? nil : " if #{optional_locals * ' && '}"
end

#continue_string_structure(prior_segments) ⇒ Object

Continue generating string for the prior segments.



552
553
554
555
556
557
558
559
# File 'lib/action_controller/routing.rb', line 552

def continue_string_structure(prior_segments)
  if prior_segments.empty?
    interpolation_statement(prior_segments)
  else
    new_priors = prior_segments[0..-2]
    prior_segments.last.string_structure(new_priors)
  end
end

#extraction_codeObject



547
548
549
# File 'lib/action_controller/routing.rb', line 547

def extraction_code
  nil
end

#interpolation_statement(prior_segments) ⇒ Object

Return a string interpolation statement for this segment and those before it.



562
563
564
565
566
# File 'lib/action_controller/routing.rb', line 562

def interpolation_statement(prior_segments)
  chunks = prior_segments.collect { |s| s.interpolation_chunk }
  chunks << interpolation_chunk
  "\"#{chunks * ''}\"#{all_optionals_available_condition(prior_segments)}"
end

#match_extraction(next_capture) ⇒ Object

Recognition



581
582
583
# File 'lib/action_controller/routing.rb', line 581

def match_extraction(next_capture)
  nil
end

#optionality_implied?Boolean

Returns true if this segment is optional? because of a default. If so, then no warning will be emitted regarding this segment.

Returns:

  • (Boolean)


589
590
591
# File 'lib/action_controller/routing.rb', line 589

def optionality_implied?
  false
end

#string_structure(prior_segments) ⇒ Object



568
569
570
# File 'lib/action_controller/routing.rb', line 568

def string_structure(prior_segments)
  optional? ? continue_string_structure(prior_segments) : interpolation_statement(prior_segments)
end