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.
-
#see ⇒ Object
readonly
Returns the value of attribute see.
Instance Method Summary collapse
- #doc_url ⇒ Object
- #id ⇒ Object
-
#initialize(method, resource, app) ⇒ MethodDescription
constructor
A new instance of MethodDescription.
- #method_apis_to_json ⇒ Object
- #params ⇒ Object
- #params_ordered ⇒ Object
- #see_url ⇒ 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 44 45 46 |
# File 'lib/restapi/method_description.rb', line 26 def initialize(method, resource, app) @method = method @resource = resource @apis = app.get_api_args @see = app.get_see desc = app.get_description || '' @full_description = Restapi.markup_to_html(desc) @errors = app.get_errors @params_ordered = app.get_params @examples = app.get_examples @examples += load_recorded_examples parent = @resource.controller.superclass if parent != ActionController::Base @parent_resource = parent.controller_name end @resource.add_method(id) 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 |
#see ⇒ Object (readonly)
Returns the value of attribute see.
24 25 26 |
# File 'lib/restapi/method_description.rb', line 24 def see @see end |
Instance Method Details
#doc_url ⇒ Object
73 74 75 |
# File 'lib/restapi/method_description.rb', line 73 def doc_url Restapi.full_url("#{@resource._id}/#{@method}") end |
#id ⇒ Object
48 49 50 |
# File 'lib/restapi/method_description.rb', line 48 def id "#{resource._id}##{method}" end |
#method_apis_to_json ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/restapi/method_description.rb', line 77 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
52 53 54 |
# File 'lib/restapi/method_description.rb', line 52 def params params_ordered.reduce({}) { |h,p| h[p.name] = p; h } end |
#params_ordered ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/restapi/method_description.rb', line 56 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 |
#see_url ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/restapi/method_description.rb', line 87 def see_url if @see method_description = Restapi[@see] if method_description.nil? raise ArgumentError.new("Method #{@see} referenced in 'see' does not exist.") end method_description.doc_url end end |
#to_json ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/restapi/method_description.rb', line 101 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, :see => @see, :see_url => see_url } end |