Skip to content

Commit

Permalink
possiblity to define a custom route formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Paret committed Feb 10, 2014
1 parent 22052df commit 624cbf3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/apipie/application.rb
Expand Up @@ -68,12 +68,7 @@ def routes_for_action(controller, method)
route.path.spec.to_s
end

path.gsub!('(.:format)', '')
path.gsub!(/[()]/, '')

Apipie.configuration.api_base_url.values.each do |values|
path.gsub!("#{values}/", '/')
end
path = Apipie.configuration.routes_path_formatter.call(path)

{ path: path, verb: human_verb(route) }
end
Expand Down
16 changes: 15 additions & 1 deletion lib/apipie/configuration.rb
Expand Up @@ -4,7 +4,8 @@ class Configuration
attr_accessor :app_name, :app_info, :copyright, :markup, :disqus_shortname,
:api_base_url, :doc_base_url, :required_by_default, :layout,
:default_version, :debug, :version_in_url, :namespaced_resources,
:validate, :validate_value, :validate_presence, :authenticate, :doc_path
:validate, :validate_value, :validate_presence, :authenticate, :doc_path,
:routes_path_formatter


alias_method :validate?, :validate
Expand Down Expand Up @@ -106,6 +107,11 @@ def api_base_url=(url)
@api_base_url[version] = url
end

def routes_path_formatter=(formatter)
raise "Apipie: routes_path_formatter : #{formatter} is not a lambda" unless formatter.class == Proc && formatter.lambda?
@routes_path_formatter = formatter
end

def initialize
@markup = Apipie::Markup::RDoc.new
@app_name = "Another API"
Expand All @@ -124,6 +130,14 @@ def initialize
@version_in_url = true
@namespaced_resources = false
@doc_path = "doc"
@routes_path_formatter = lambda do |path|
path.gsub!('(.:format)', '')
path.gsub!(/[()]/, '')
Apipie.configuration.api_base_url.values.each do |values|
path.gsub!("#{values}/", '/')
end
path
end
end
end
end

0 comments on commit 624cbf3

Please sign in to comment.