Class: Diesel::Middleware::SetPathParameter

Inherits:
SetParameterBase show all
Defined in:
lib/diesel/middleware/set_path_parameter.rb

Instance Method Summary collapse

Methods inherited from SetParameterBase

#call

Constructor Details

#initialize(app, options) ⇒ SetPathParameter

Returns a new instance of SetPathParameter.



7
8
9
10
# File 'lib/diesel/middleware/set_path_parameter.rb', line 7

def initialize(app, options)
  super
  @regex = Regexp.new(Regexp.quote("{#{@name}}"))
end

Instance Method Details

#apply_parameter_value(env, value) ⇒ Object



12
13
14
15
# File 'lib/diesel/middleware/set_path_parameter.rb', line 12

def apply_parameter_value(env, value)
  uri = env[:url]
  uri.resource_path = uri.resource_path.gsub(@regex, value.to_s)
end