Class: Restapi::MethodDescription
- Inherits:
-
Object
- Object
- Restapi::MethodDescription
- Defined in:
- lib/restapi/method_description.rb
Defined Under Namespace
Classes: Api
Instance Attribute Summary collapse
-
#apis ⇒ Object
readonly
Returns the value of attribute apis.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#full_description ⇒ Object
readonly
Returns the value of attribute full_description.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #doc_url ⇒ Object
-
#initialize(method, resource, app) ⇒ MethodDescription
constructor
A new instance of MethodDescription.
- #method_apis_to_json ⇒ Object
- #params ⇒ Object
- #params_ordered ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(method, resource, app) ⇒ MethodDescription
Returns a new instance of MethodDescription.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/restapi/method_description.rb', line 26 def initialize(method, resource, app) @method = method @resource = resource @apis = app.get_api_args desc = app.get_description || '' @full_description = Restapi.markup_to_html(desc) @errors = app.get_errors @params_ordered = app.get_params @examples = app.get_examples parent = @resource.controller.superclass if parent != ActionController::Base @parent_resource = parent.controller_name end @resource.add_method("#{resource._id}##{method}") end |
Instance Attribute Details
#apis ⇒ Object (readonly)
Returns the value of attribute apis.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def apis @apis end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def errors @errors end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def examples @examples end |
#full_description ⇒ Object (readonly)
Returns the value of attribute full_description.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def full_description @full_description end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def method @method end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def resource @resource end |
Instance Method Details
#doc_url ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/restapi/method_description.rb', line 66 def doc_url [ ENV["RAILS_RELATIVE_URL_ROOT"], Restapi.configuration.doc_base_url, "/#{@resource._id}/#{@method}" ].join end |
#method_apis_to_json ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/restapi/method_description.rb', line 74 def method_apis_to_json @apis.each.collect do |api| { :api_url => api.api_url, :http_method => api.http_method.to_s, :short_description => api.short_description } end end |
#params ⇒ Object
45 46 47 |
# File 'lib/restapi/method_description.rb', line 45 def params params_ordered.reduce({}) { |h,p| h[p.name] = p; h } end |
#params_ordered ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/restapi/method_description.rb', line 49 def params_ordered all_params = [] # get params from parent resource description if @parent_resource parent = Restapi.get_resource_description(@parent_resource) merge_params(all_params, parent._params_ordered) if parent end # get params from actual resource description if @resource merge_params(all_params, resource._params_ordered) end merge_params(all_params, @params_ordered) all_params.find_all(&:validator) end |
#to_json ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/restapi/method_description.rb', line 84 def to_json { :doc_url => doc_url, :name => @method, :apis => method_apis_to_json, :full_description => @full_description, :errors => @errors, :params => params_ordered.map(&:to_json).flatten, :examples => @examples } end |