Class: Apipie::MethodDescription
- Inherits:
-
Object
- Object
- Apipie::MethodDescription
- Defined in:
- lib/apipie/method_description.rb
Defined Under Namespace
Classes: Api
Instance Attribute Summary collapse
-
#apis ⇒ Object
readonly
Returns the value of attribute apis.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#formats ⇒ Object
readonly
Returns the value of attribute formats.
-
#full_description ⇒ Object
readonly
Returns the value of attribute full_description.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#see ⇒ Object
readonly
Returns the value of attribute see.
-
#show ⇒ Object
readonly
Returns the value of attribute show.
Instance Method Summary collapse
- #create_api_url(api) ⇒ Object
- #doc_url ⇒ Object
- #errors ⇒ Object
-
#from_concern? ⇒ Boolean
was the description defines in a module instead of directly in controller?.
- #id ⇒ Object
-
#initialize(method, resource, dsl_data) ⇒ MethodDescription
constructor
A new instance of MethodDescription.
- #method_apis_to_json(lang = nil) ⇒ Object
- #params ⇒ Object
- #params_ordered ⇒ Object
- #params_ordered_self ⇒ Object
- #returns ⇒ Object
- #returns_self ⇒ Object
- #tag_list ⇒ Object
- #to_json(lang = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(method, resource, dsl_data) ⇒ MethodDescription
Returns a new instance of MethodDescription.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/apipie/method_description.rb', line 23 def initialize(method, resource, dsl_data) @method = method.to_s @resource = resource @from_concern = dsl_data[:from_concern] @apis = api_data(dsl_data).map do |mthd, path, desc, opts| MethodDescription::Api.new(mthd, concern_subst(path), concern_subst(desc), opts) end desc = dsl_data[:description] || '' @full_description = Apipie.markup_to_html(desc) @errors = dsl_data[:errors].map do |args| Apipie::ErrorDescription.from_dsl_data(args) end @tag_list = dsl_data[:tag_list] @returns = dsl_data[:returns].map do |code,args| Apipie::ResponseDescription.from_dsl_data(self, code, args) end @see = dsl_data[:see].map do |args| Apipie::SeeDescription.new(args) end @formats = dsl_data[:formats] @examples = dsl_data[:examples] @examples += load_recorded_examples = dsl_data[:meta] @params_ordered = dsl_data[:params].map do |args| Apipie::ParamDescription.from_dsl_data(self, args) end.reject{|p| p.response_only? } @params_ordered = ParamDescription.unify(@params_ordered) @headers = dsl_data[:headers] @show = if dsl_data.has_key? :show dsl_data[:show] else true end end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def apis @apis end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def examples @examples end |
#formats ⇒ Object (readonly)
Returns the value of attribute formats.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def formats @formats end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def full_description @full_description end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def headers @headers end |
#metadata ⇒ Object
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/apipie/method_description.rb', line 21 def end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def method @method end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def resource @resource end |
#see ⇒ Object (readonly)
Returns the value of attribute see.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def see @see end |
#show ⇒ Object (readonly)
Returns the value of attribute show.
20 21 22 |
# File 'lib/apipie/method_description.rb', line 20 def show @show end |
Instance Method Details
#create_api_url(api) ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'lib/apipie/method_description.rb', line 153 def create_api_url(api) path = api.path unless api.from_routes path = "#{@resource._api_base_url}#{path}" end path = path[0..-2] if path[-1..-1] == '/' return path end |
#doc_url ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/apipie/method_description.rb', line 145 def doc_url crumbs = [] crumbs << @resource._version if Apipie.configuration.version_in_url crumbs << @resource._id crumbs << @method Apipie.full_url crumbs.join('/') end |
#errors ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/apipie/method_description.rb', line 124 def errors return @merged_errors if @merged_errors @merged_errors = [] if @resource resource_errors = @resource._errors_args.map do |args| Apipie::ErrorDescription.from_dsl_data(args) end # exclude overwritten parent errors @merged_errors = resource_errors.find_all do |err| !@errors.any? { |e| e.code == err.code } end end @merged_errors.concat(@errors) return @merged_errors end |
#from_concern? ⇒ Boolean
was the description defines in a module instead of directly in controller?
200 201 202 |
# File 'lib/apipie/method_description.rb', line 200 def from_concern? @from_concern end |
#id ⇒ Object
68 69 70 |
# File 'lib/apipie/method_description.rb', line 68 def id "#{resource._id}##{method}" end |
#method_apis_to_json(lang = nil) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/apipie/method_description.rb', line 162 def method_apis_to_json(lang = nil) @apis.each.collect do |api| { :api_url => create_api_url(api), :http_method => api.http_method.to_s, :short_description => Apipie.app.translate(api.short_description, lang), :deprecated => resource._deprecated || api.[:deprecated] } end end |
#params ⇒ Object
72 73 74 |
# File 'lib/apipie/method_description.rb', line 72 def params params_ordered.reduce(ActiveSupport::OrderedHash.new) { |h,p| h[p.name] = p; h } end |
#params_ordered ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/apipie/method_description.rb', line 80 def params_ordered all_params = [] parent = Apipie.get_resource_description(@resource.controller.superclass) # get params from parent resource description [parent, @resource].compact.each do |resource| resource_params = resource._params_args.map do |args| Apipie::ParamDescription.from_dsl_data(self, args) end merge_params(all_params, resource_params) end merge_params(all_params, @params_ordered) all_params.find_all(&:validator) end |
#params_ordered_self ⇒ Object
76 77 78 |
# File 'lib/apipie/method_description.rb', line 76 def params_ordered_self @params_ordered end |
#returns ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/apipie/method_description.rb', line 109 def returns all_returns = [] parent = Apipie.get_resource_description(@resource.controller.superclass) # get response descriptions from parent resource description [parent, @resource].compact.each do |resource| resource_returns = resource._returns_args.map do |code, args| Apipie::ResponseDescription.from_dsl_data(self, code, args) end merge_returns(all_returns, resource_returns) end merge_returns(all_returns, @returns) end |
#returns_self ⇒ Object
96 97 98 |
# File 'lib/apipie/method_description.rb', line 96 def returns_self @returns end |
#tag_list ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/apipie/method_description.rb', line 100 def tag_list all_tag_list = [] parent = Apipie.get_resource_description(@resource.controller.superclass) # get tags from parent resource description = [parent, @resource].compact.flat_map { |resource| resource._tag_list_arg } Apipie::TagListDescription.new(( + @tag_list).uniq.compact) end |
#to_json(lang = nil) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/apipie/method_description.rb', line 181 def to_json(lang=nil) { :doc_url => doc_url, :name => @method, :apis => method_apis_to_json(lang), :formats => formats, :full_description => Apipie.app.translate(@full_description, lang), :errors => errors.map(&:to_json), :params => params_ordered.map{ |param| param.to_json(lang) }.flatten, :returns => @returns.map{ |return_item| return_item.to_json(lang) }.flatten, :examples => @examples, :metadata => , :see => see.map(&:to_json), :headers => headers, :show => @show } end |
#version ⇒ Object
141 142 143 |
# File 'lib/apipie/method_description.rb', line 141 def version resource._version end |