Class: GrapeDocs::Endpoint
- Inherits:
-
Object
- Object
- GrapeDocs::Endpoint
- Defined in:
- lib/grape_docs/endpoint.rb
Instance Attribute Summary collapse
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #body_params ⇒ Object
-
#initialize(api, endpoint) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #path_params ⇒ Object
- #query_params ⇒ Object
Constructor Details
#initialize(api, endpoint) ⇒ Endpoint
Returns a new instance of Endpoint.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/grape_docs/endpoint.rb', line 5 def initialize(api, endpoint) = endpoint.[:route_options] @title = [:description] || endpoint.[:path].first @detail = [:detail] parent_path = File.join(endpoint.inheritable_setting.namespace_stackable[:mount_path]) @path = File.join(parent_path, endpoint.[:path].first.to_s) @host = GrapeDocs.config[:api_host] @url = File.join(@host, @path) @params = [:params].map { |p| p[1].merge(name: p[0]) } @method = endpoint.[:method].first @status_code = 200 if [:entity] entity = [:entity].kind_of?(Array) ? [:entity][1] : [:entity] @status_code = [:entity].kind_of?(Array) ? [:entity][0] : 200 unless entity.nil? @model = entity.documentation.map { |p| p[1].merge(name: p[0]) } @response = build_response(@model) end end end |
Instance Attribute Details
#detail ⇒ Object (readonly)
Returns the value of attribute detail.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def detail @detail end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def host @host end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def method @method end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def model @model end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def params @params end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def path @path end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def response @response end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def status_code @status_code end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/grape_docs/endpoint.rb', line 3 def url @url end |
Instance Method Details
#body_params ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/grape_docs/endpoint.rb', line 33 def body_params return [] if method == "GET" names = path.scan(/:([a-z0-9_]+)/).map(&:first) params.reject do |param| names.include?(param[:name]) end end |
#path_params ⇒ Object
26 27 28 29 30 31 |
# File 'lib/grape_docs/endpoint.rb', line 26 def path_params names = path.scan(/:([a-z0-9_]+)/).map(&:first) params.select do |param| names.include?(param[:name]) end end |
#query_params ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/grape_docs/endpoint.rb', line 41 def query_params return [] if method != "GET" names = path.scan(/:([a-z0-9_]+)/).map(&:first) params.reject do |param| names.include?(param[:name]) end end |