Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/apipie/dsl_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,16 @@ def apipie_update_methods(methods, *args, &block)
# backwards compatibility
alias apipie_update_params apipie_update_methods

def apipie_lazy_update_methods(methods, &block)
methods.each do |method|
method_desc = Apipie.get_method_description(self, method)
unless method_desc
raise "Could not find method description for #{self}##{method}. Was the method defined?"
end
method_desc.lazy_update_blocks << [self, block]
end
end

def _apipie_concern_subst
@_apipie_concern_subst ||= {
controller_path: self.controller_path,
Expand Down Expand Up @@ -575,6 +585,9 @@ def included(controller)
_apipie_concern_update_api_blocks.each do |(methods, block)|
controller.apipie_update_methods(methods, &block)
end
_apipie_concern_lazy_update_api_blocks.each do |(methods, block)|
controller.apipie_lazy_update_methods(methods, &block)
end
end

def _apipie_concern_data
Expand All @@ -585,6 +598,10 @@ def _apipie_concern_update_api_blocks
@_apipie_concern_update_api_blocks ||= []
end

def _apipie_concern_lazy_update_api_blocks
@_apipie_concern_lazy_update_api_blocks ||= []
end

def apipie_concern?
true
end
Expand All @@ -604,6 +621,10 @@ def update_api(*methods, &block)
_apipie_concern_update_api_blocks << [methods, block]
end

def lazy_update_api(*methods, &block)
_apipie_concern_lazy_update_api_blocks << [methods, block]
end

end

class ResourceDescriptionDsl
Expand Down
12 changes: 11 additions & 1 deletion lib/apipie/method_description.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Apipie
class MethodDescription
attr_reader :full_description, :method, :resource, :apis, :examples, :see, :formats, :headers, :show
attr_accessor :metadata
attr_accessor :metadata, :lazy_update_blocks

def initialize(method, resource, dsl_data)
@method = method.to_s
Expand Down Expand Up @@ -43,6 +43,7 @@ def initialize(method, resource, dsl_data)
else
true
end
@lazy_update_blocks = []
end

def id
Expand Down Expand Up @@ -73,6 +74,14 @@ def params_ordered
all_params.find_all(&:validator)
end

def eval_lazy_update_blocks
lazy_update_blocks.each do |(context, block)|
dsl_data = context._apipie_eval_dsl(&block)
context._apipie_update_params(self, dsl_data)
context._apipie_update_meta(self, dsl_data)
end
end

def returns_self
@returns
end
Expand Down Expand Up @@ -159,6 +168,7 @@ def formats
end

def to_json(lang = nil)
eval_lazy_update_blocks
{
:doc_url => doc_url,
:name => @method,
Expand Down
Loading