Module: RocketPants::Routing
- Defined in:
- lib/rocket_pants/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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rocket_pants/routing.rb', line 9 def rocket_pants( = {}, &blk) versions = extract_rocket_pants_versions defaults = {:format => 'json'} if (optional_prefix = .delete(:allow_prefix)) versions.map! { |v| "#{optional_prefix}?#{v}" } defaults[:rp_prefix] = {:text => optional_prefix.to_s, :required => false} elsif (required_prefix = .delete(:require_prefix)) versions.map! { |v| "#{required_prefix}#{v}" } defaults[:rp_prefix] = {:text => required_prefix.to_s, :required => true} end versions_regexp = /(#{versions.uniq.join("|")})/ raise ArgumentError, 'please provide at least one version' if versions.empty? = .deep_merge({ :constraints => {:version => versions_regexp}, :path => ':version', :defaults => defaults }) scope , &blk end |