Module: RocketShorts::Routing
- Defined in:
- lib/rocket_shorts/routing.rb
Instance Method Summary collapse
-
#rocket_pants(options = {}, &blk) ⇒ Object
(also: #api)
Scopes a set of given api routes, allowing for option versions.
Instance Method Details
#rocket_pants(options = {}, &blk) ⇒ Object Also known as: api
Scopes a set of given api routes, allowing for option versions.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rocket_shorts/routing.rb', line 15 def rocket_pants( = {}, &blk) versions = (Array(.delete(:versions)) + Array(.delete(:version))).flatten.map(&:to_s) versions.each do |version| raise ArgumentError, "Got invalid version: '#{version}'" unless version =~ /\A\d+\Z/ end versions_regexp = /(#{versions.uniq.join("|")})/ raise ArgumentError, 'please provide atleast one version' if versions.empty? = .deep_merge({ constraints: RoutingConstraints.new(versions: versions_regexp, default: !!.delete(:default)), }) namespace :api, defaults: {format: 'json'} do scope , &blk end end |