Class: RoutingFilter::ForceExtension

Inherits:
Base
  • Object
show all
Defined in:
lib/routing_filter/force_extension.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#chain, #options

Instance Method Summary collapse

Methods inherited from Base

#predecessor, #run, #run_reverse, #successor

Constructor Details

#initialize(*args) ⇒ ForceExtension

Returns a new instance of ForceExtension.



7
8
9
10
11
# File 'lib/routing_filter/force_extension.rb', line 7

def initialize(*args)
  super
  @extension ||= 'html'
  @exclude = %r(^(http.?://[^/]+)?\/?$) if @exclude.nil?
end

Instance Attribute Details

#excludeObject (readonly)

Returns the value of attribute exclude.



5
6
7
# File 'lib/routing_filter/force_extension.rb', line 5

def exclude
  @exclude
end

#extensionObject (readonly)

Returns the value of attribute extension.



5
6
7
# File 'lib/routing_filter/force_extension.rb', line 5

def extension
  @extension
end

Instance Method Details

#around_generate(*args, &block) ⇒ Object



18
19
20
21
22
23
# File 'lib/routing_filter/force_extension.rb', line 18

def around_generate(*args, &block)
  returning yield do |result|
    url = result.is_a?(Array) ? result.first : result
    append_extension!(url) if append_extension?(url)
  end
end

#around_recognize(path, env) {|path, env| ... } ⇒ Object

Yields:

  • (path, env)


13
14
15
16
# File 'lib/routing_filter/force_extension.rb', line 13

def around_recognize(path, env, &block)
  extract_extension!(path) unless excluded?(path)
  yield(path, env)
end