Module: RailsLegacyMapper::RouteSetExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/rails_legacy_mapper/route_set_extensions.rb
Overview
:nodoc:
Constant Summary collapse
- CONTROLLER_REGEXP =
/[_a-zA-Z0-9]+/
Instance Method Summary collapse
- #controller_constraints ⇒ Object
- #eval_block_with_legacy_mapper(block) ⇒ Object
- #in_memory_controller_namespaces ⇒ Object
- #initialize_with_legacy_mapper(request_class = ActionDispatch::Request) ⇒ Object
Instance Method Details
#controller_constraints ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/rails_legacy_mapper/route_set_extensions.rb', line 21 def controller_constraints @controller_constraints ||= begin namespaces = controller_namespaces + in_memory_controller_namespaces source = namespaces.map { |ns| "#{Regexp.escape(ns)}/#{CONTROLLER_REGEXP.source}" } source << CONTROLLER_REGEXP.source Regexp.compile(source.sort.reverse.join('|')) end end |
#eval_block_with_legacy_mapper(block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rails_legacy_mapper/route_set_extensions.rb', line 40 def eval_block_with_legacy_mapper(block) mapper = ActionDispatch::Routing::Mapper.new(self) if block.arity == 1 mapper.instance_exec(RailsLegacyMapper::Mapper.new(self), &block) elsif default_scope mapper.with_default_scope(default_scope, &block) else mapper.instance_exec(&block) end end |
#in_memory_controller_namespaces ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_legacy_mapper/route_set_extensions.rb', line 30 def in_memory_controller_namespaces namespaces = Set.new ActionController::Base.descendants.each do |klass| next if klass.anonymous? namespaces << klass.name.underscore.split('/')[0...-1].join('/') end namespaces.delete('') namespaces end |
#initialize_with_legacy_mapper(request_class = ActionDispatch::Request) ⇒ Object
16 17 18 19 |
# File 'lib/rails_legacy_mapper/route_set_extensions.rb', line 16 def initialize_with_legacy_mapper(request_class = ActionDispatch::Request) initialize_without_legacy_mapper self.controller_namespaces = Set.new end |