Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

api_version keyword

Specify what version does the method belong it. One method can belong
to more versions.
  • Loading branch information...
commit 0ecf0b7baa15fade116abb3d6e5efd0ba3be498a 1 parent de11c0f
@iNecas iNecas authored
Showing with 26 additions and 18 deletions.
  1. +20 −17 lib/apipie/application.rb
  2. +6 −1 lib/apipie/dsl_definition.rb
View
37 lib/apipie/application.rb
@@ -12,7 +12,8 @@ class Engine < Rails::Engine
end
end
- attr_accessor :last_api_args, :last_errors, :last_params, :last_description, :last_examples, :last_see, :last_formats
+ attr_accessor :last_api_args, :last_errors, :last_params, :last_description,
+ :last_examples, :last_see, :last_formats, :last_api_versions
attr_reader :resource_descriptions
def initialize
@@ -26,30 +27,31 @@ def available_versions
end
# create new method api description
- def define_method_description(controller, method_name)
- if ignored?(controller, method_name)
- clear_last
- return
- end
+ def define_method_description(controller, method_name, versions = [])
+ return if ignored?(controller, method_name)
+
+ versions = [Apipie.configuration.default_version] if versions.empty?
+
+ versions.each do |version|
+ resource_name_with_version = "#{version}##{get_resource_name(controller)}"
+ resource_description = get_resource_description(resource_name_with_version)
- resource_description = get_resource_description(controller)
- if resource_description.nil?
- resource_description = define_resource_description(controller)
+ if resource_description.nil?
+ resource_description = define_resource_description(controller, version)
+ end
+
+ method_description = Apipie::MethodDescription.new(method_name, resource_description, self)
+ resource_description.add_method_description(method_description)
end
- method_description = Apipie::MethodDescription.new(method_name, resource_description, self)
- resource_description.add_method_description(method_description)
end
# create new resource api description
- def define_resource_description(controller, &block)
- if ignored?(controller)
- clear_last
- return
- end
+ def define_resource_description(controller, version = nil, &block)
+ return if ignored?(controller)
resource_name = get_resource_name(controller)
resource_description = Apipie::ResourceDescription.new(controller, resource_name, &block)
- version = get_resource_version(resource_description)
+ version ||= get_resource_version(resource_description)
@resource_descriptions[version] ||= {}
Apipie.debug("@resource_descriptions[#{version}][#{resource_name}] = #{resource_description}")
@@ -143,6 +145,7 @@ def clear_last
@last_examples = []
@last_see = nil
@last_formats = []
+ @last_api_versions = []
end
# Return the current description, clearing it in the process.
View
7 lib/apipie/dsl_definition.rb
@@ -32,6 +32,11 @@ def api(method, path, desc = nil) #:doc:
Apipie.add_method_description_args(method, path, desc)
end
+ # What version is the api available
+ def api_version version
+ Apipie.last_api_versions << version
+ end
+
# Describe the next method.
#
# Example:
@@ -112,7 +117,7 @@ def method_added(method_name) #:doc:
# remove method description if exists and create new one
Apipie.remove_method_description(self, method_name)
- description = Apipie.define_method_description(self, method_name)
+ description = Apipie.define_method_description(self, method_name, Apipie.last_api_versions)
# redefine method only if validation is turned on
if description && Apipie.configuration.validate == true
Please sign in to comment.
Something went wrong with that request. Please try again.