Class: Waffle::Maker::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/waffle/maker/matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(waf_path, routes) ⇒ Matcher

Returns a new instance of Matcher.



8
9
10
11
# File 'lib/waffle/maker/matcher.rb', line 8

def initialize(waf_path, routes)
  @waf_path = waf_path.to_s.chomp('/')
  @routes = routes
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



6
7
8
# File 'lib/waffle/maker/matcher.rb', line 6

def routes
  @routes
end

#waf_pathObject (readonly)

Returns the value of attribute waf_path.



6
7
8
# File 'lib/waffle/maker/matcher.rb', line 6

def waf_path
  @waf_path
end

Instance Method Details

#matched?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/waffle/maker/matcher.rb', line 13

def matched?
  return true if routes.include?(waf_path)

  routes.any? do |route|
    -> {
      route = params_route_2_regex_route(route)
      return false if route.start_with?("/#{rep_regex}")
      /#{route}$/.match?(waf_path)
    }.call
  end
end

#rep_regexObject



26
27
28
# File 'lib/waffle/maker/matcher.rb', line 26

def rep_regex
  '(\w+)'
end