Class: RoutingFilter::SectionPath

Inherits:
Filter
  • Object
show all
Extended by:
ActiveSupport::Memoizable
Defined in:
lib/adva/routing_filters/section_path.rb

Instance Method Summary collapse

Instance Method Details

#around_generate(params, &block) ⇒ Object


25
26
27
28
29
30
31
32
33
34
# File 'lib/adva/routing_filters/section_path.rb', line 25

def around_generate(params, &block)
  yield.tap do |path|
    # p "#{self.class.name}: #{path}"
    if !excluded?(path)
      search, replace = *generation(path)
      path.sub!(search) { "#{replace}#{$3}" } if search
      path.replace("/#{path}") unless path[0, 1] == '/'
    end
  end
end

#around_recognize(path, env, &block) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/adva/routing_filters/section_path.rb', line 16

def around_recognize(path, env, &block)
  # p "#{self.class.name}: #{path}"
  if !excluded?(path)
    search, replace = recognition(host(env), path)
    path.sub!(%r(^/([\w]{2,4}/)?(#{search})(?=/|\.|\?|$)), "/#{$1}#{replace}#{$3}") if search
  end
  yield
end