Class: Xing::SpecDoc::Patterner
- Inherits:
-
Object
- Object
- Xing::SpecDoc::Patterner
- Defined in:
- lib/xing/specdoc/patterner.rb
Instance Attribute Summary collapse
-
#rails_routes ⇒ Object
readonly
Returns the value of attribute rails_routes.
Instance Method Summary collapse
- #build(req) ⇒ Object
-
#initialize(rails_routes, route_set = nil) ⇒ Patterner
constructor
A new instance of Patterner.
- #route_map ⇒ Object
- #route_set ⇒ Object
Constructor Details
#initialize(rails_routes, route_set = nil) ⇒ Patterner
Returns a new instance of Patterner.
4 5 6 7 |
# File 'lib/xing/specdoc/patterner.rb', line 4 def initialize(rails_routes, route_set=nil) @rails_routes = rails_routes @route_set = route_set end |
Instance Attribute Details
#rails_routes ⇒ Object (readonly)
Returns the value of attribute rails_routes.
8 9 10 |
# File 'lib/xing/specdoc/patterner.rb', line 8 def rails_routes @rails_routes end |
Instance Method Details
#build(req) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/xing/specdoc/patterner.rb', line 23 def build(req) route_set.recognize(req) do |route, matches, params| rails_route = route_map[route] path_spec = :unrecognized segment_keys = {} if route_map.has_key?(route) rails_route = route_map[route] path_spec = rails_route.path.spec.to_s segment_keys = rails_route.segment_keys return path_spec.sub(/\(\.:format\)/,"") end end return nil end |
#route_map ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/xing/specdoc/patterner.rb', line 10 def route_map @route_map ||= begin ad_routes_array = rails_routes.routes rack_routes_array = rails_routes.set.instance_eval{ @routes } Hash[ rack_routes_array.zip(ad_routes_array) ] end end |
#route_set ⇒ Object
19 20 21 |
# File 'lib/xing/specdoc/patterner.rb', line 19 def route_set @route_set ||= Rails.application.routes.router end |