Class: RouteMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actions: nil, params: nil, methods: nil, formats: nil, aliases: nil, allowed_param_values: nil) ⇒ RouteMatcher

Returns a new instance of RouteMatcher.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/route_matcher.rb', line 8

def initialize(
  actions: nil,
  params: nil,
  methods: nil,
  formats: nil,
  aliases: nil,
  allowed_param_values: nil
)
  @actions = Array(actions) if actions
  @params = Array(params) if params
  @methods = Array(methods) if methods
  @formats = Array(formats) if formats
  @aliases = aliases
  @allowed_param_values = allowed_param_values
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



6
7
8
# File 'lib/route_matcher.rb', line 6

def actions
  @actions
end

#aliasesObject (readonly)

Returns the value of attribute aliases.



6
7
8
# File 'lib/route_matcher.rb', line 6

def aliases
  @aliases
end

#allowed_param_valuesObject (readonly)

Returns the value of attribute allowed_param_values.



6
7
8
# File 'lib/route_matcher.rb', line 6

def allowed_param_values
  @allowed_param_values
end

#formatsObject (readonly)

Returns the value of attribute formats.



6
7
8
# File 'lib/route_matcher.rb', line 6

def formats
  @formats
end

#methodsObject (readonly)

Returns the value of attribute methods.



6
7
8
# File 'lib/route_matcher.rb', line 6

def methods
  @methods
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/route_matcher.rb', line 6

def params
  @params
end

Instance Method Details

#match?(env:) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/route_matcher.rb', line 36

def match?(env:)
  request = ActionDispatch::Request.new(env)

  action_allowed?(request) && params_allowed?(request) && method_allowed?(request) &&
    format_allowed?(request)
end

#with_allowed_param_values(new_allowed_param_values) ⇒ Object

Return an identical route matcher, with the allowed_param_values replaced



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

def with_allowed_param_values(new_allowed_param_values)
  RouteMatcher.new(
    actions: actions,
    params: params,
    methods: methods,
    formats: formats,
    aliases: aliases,
    allowed_param_values: new_allowed_param_values,
  )
end