Class: RailsContractSync::Static::RouteExtractor
- Inherits:
-
Object
- Object
- RailsContractSync::Static::RouteExtractor
- Defined in:
- lib/rails_contract_sync/static/route_extractor.rb
Constant Summary collapse
- VERBS =
%w[GET POST PUT PATCH DELETE].freeze
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(route_set) ⇒ RouteExtractor
constructor
A new instance of RouteExtractor.
Constructor Details
#initialize(route_set) ⇒ RouteExtractor
Returns a new instance of RouteExtractor.
6 7 8 |
# File 'lib/rails_contract_sync/static/route_extractor.rb', line 6 def initialize(route_set) @route_set = route_set end |
Instance Method Details
#extract ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails_contract_sync/static/route_extractor.rb', line 10 def extract @route_set.routes.filter_map do |route| controller = route.defaults[:controller] action = route.defaults[:action] next if controller.nil? || action.nil? verb = VERBS.find { |m| route.verb.to_s.include?(m) } next if verb.nil? spec = route.path.spec.to_s.sub(/\(\.:format\)\z/, "") { verb: verb, path: spec.gsub(/:([a-z_]+)/) { "{#{Regexp.last_match(1)}}" }, controller: controller, action: action, path_params: spec.scan(/:([a-z_]+)/).flatten - ["format"] } end end |