Class: ApipieDSL::MethodDescription
- Inherits:
-
Object
- Object
- ApipieDSL::MethodDescription
- Defined in:
- lib/apipie_dsl/method_description.rb
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#full_description ⇒ Object
Returns the value of attribute full_description.
-
#klass ⇒ Object
(also: #class_description)
readonly
Returns the value of attribute klass.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#raises ⇒ Object
Returns the value of attribute raises.
-
#returns ⇒ Object
Returns the value of attribute returns.
-
#see ⇒ Object
readonly
Returns the value of attribute see.
-
#short_description ⇒ Object
Returns the value of attribute short_description.
-
#show ⇒ Object
Returns the value of attribute show.
-
#signature ⇒ Object
readonly
Returns the value of attribute signature.
Class Method Summary collapse
Instance Method Summary collapse
- #doc_url(section = nil) ⇒ Object
- #docs(section = nil, lang = nil) ⇒ Object
- #id ⇒ Object
-
#initialize(name, klass, dsl_data) ⇒ MethodDescription
constructor
A new instance of MethodDescription.
- #param_descriptions ⇒ Object
- #params ⇒ Object
- #plain_params ⇒ Object
- #tag_list ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(name, klass, dsl_data) ⇒ MethodDescription
Returns a new instance of MethodDescription.
15 16 17 18 19 20 21 22 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 |
# File 'lib/apipie_dsl/method_description.rb', line 15 def initialize(name, klass, dsl_data) @name = name.to_s @klass = klass desc = dsl_data[:description] || '' @full_description = ApipieDSL.markup_to_html(desc) @short_description = dsl_data[:short_description] || '' @params = (dsl_data[:params] || []).map do |args| ApipieDSL::ParameterDescription.from_dsl_data(self, args) end @params = ApipieDSL::ParameterDescription.unify(@params) @raises = (dsl_data[:raises] || []).map do |args| ApipieDSL::ExceptionDescription.from_dsl_data(args) end # Every method in Ruby returns an onject dsl_data[:returns] = [{ object_of: Object }] if dsl_data[:returns].nil? @returns = ApipieDSL::ReturnDescription.from_dsl_data(self, dsl_data[:returns]) @tag_list = dsl_data[:tag_list] @see = (dsl_data[:see] || []).map do |method, | [:scope] ||= @klass ApipieDSL::SeeDescription.new(method, ) end @metadata = dsl_data[:meta] @show = dsl_data[:show].nil? ? true : dsl_data[:show] @examples = (dsl_data[:examples] || []).select do |example| next example if example[:for].nil? example[:for].to_s == @name end @aliases = dsl_data[:aliases] @signature = dsl_data[:signature] end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def aliases @aliases end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
5 6 7 |
# File 'lib/apipie_dsl/method_description.rb', line 5 def examples @examples end |
#full_description ⇒ Object
Returns the value of attribute full_description.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def full_description @full_description end |
#klass ⇒ Object (readonly) Also known as: class_description
Returns the value of attribute klass.
5 6 7 |
# File 'lib/apipie_dsl/method_description.rb', line 5 def klass @klass end |
#metadata ⇒ Object
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/apipie_dsl/method_description.rb', line 5 def name @name end |
#raises ⇒ Object
Returns the value of attribute raises.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def raises @raises end |
#returns ⇒ Object
Returns the value of attribute returns.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def returns @returns end |
#see ⇒ Object (readonly)
Returns the value of attribute see.
5 6 7 |
# File 'lib/apipie_dsl/method_description.rb', line 5 def see @see end |
#short_description ⇒ Object
Returns the value of attribute short_description.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def short_description @short_description end |
#show ⇒ Object
Returns the value of attribute show.
6 7 8 |
# File 'lib/apipie_dsl/method_description.rb', line 6 def show @show end |
#signature ⇒ Object (readonly)
Returns the value of attribute signature.
5 6 7 |
# File 'lib/apipie_dsl/method_description.rb', line 5 def signature @signature end |
Class Method Details
.from_dsl_data(klass, args) ⇒ Object
10 11 12 13 |
# File 'lib/apipie_dsl/method_description.rb', line 10 def self.from_dsl_data(klass, args) name, dsl_data = args ApipieDSL::MethodDescription.new(name, klass, dsl_data) end |
Instance Method Details
#doc_url(section = nil) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/apipie_dsl/method_description.rb', line 88 def doc_url(section = nil) crumbs = [] crumbs << @klass.version if ApipieDSL.configuration.version_in_url crumbs << section if section crumbs << @klass.id crumbs << @name ApipieDSL.full_url(crumbs.join('/')).gsub('?', '%3F') end |
#docs(section = nil, lang = nil) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/apipie_dsl/method_description.rb', line 97 def docs(section = nil, lang = nil) { doc_url: doc_url(section), name: @name, full_description: ApipieDSL.translate(@full_description, lang), short_description: ApipieDSL.translate(@short_description, lang), params: param_descriptions.map { |param| param.docs(lang) }.flatten, raises: raises.map(&:docs), returns: @returns.docs(lang), metadata: @metadata, see: see.map(&:docs), show: @show, examples: @examples, aliases: aliases, signature: signature } end |
#id ⇒ Object
61 62 63 |
# File 'lib/apipie_dsl/method_description.rb', line 61 def id "#{klass.id}##{name}" end |
#param_descriptions ⇒ Object
74 75 76 |
# File 'lib/apipie_dsl/method_description.rb', line 74 def param_descriptions @params.select(&:validator) end |
#params ⇒ Object
69 70 71 72 |
# File 'lib/apipie_dsl/method_description.rb', line 69 def params param_descriptions.each_with_object({}) { |p, h| h[p.name] = p } .sort.to_h end |
#plain_params ⇒ Object
65 66 67 |
# File 'lib/apipie_dsl/method_description.rb', line 65 def plain_params @params end |
#tag_list ⇒ Object
78 79 80 81 82 |
# File 'lib/apipie_dsl/method_description.rb', line 78 def tag_list parent = ApipieDSL.get_class_description(ApipieDSL.superclass_for(@klass.class)) = [parent, @klass].compact.flat_map(&:tag_list_arg) ApipieDSL::TagListDescription.new(( + @tag_list).uniq.compact) end |
#version ⇒ Object
84 85 86 |
# File 'lib/apipie_dsl/method_description.rb', line 84 def version klass.version end |