Module: Grape::DSL::Desc
Instance Attribute Summary
Attributes included from Settings
#inheritable_setting, #top_level_setting
Instance Method Summary collapse
-
#desc(description, options = {}) { ... } ⇒ Object
Add a description to the next namespace or function.
-
#desc_container ⇒ Object
Returns an object which configures itself via an instance-context DSL.
- #description_field(field, value = nil) ⇒ Object
- #unset_description_field(field) ⇒ Object
Methods included from Settings
#api_class_setting, #get_or_set, #global_setting, #namespace_end, #namespace_inheritable, #namespace_inheritable_to_nil, #namespace_reverse_stackable, #namespace_reverse_stackable_with_hash, #namespace_setting, #namespace_stackable, #namespace_stackable_with_hash, #namespace_start, #route_end, #route_setting, #unset, #unset_api_class_setting, #unset_global_setting, #unset_namespace_inheritable, #unset_namespace_setting, #unset_namespace_stackable, #unset_route_setting, #within_namespace
Instance Method Details
#desc(description, options = {}) { ... } ⇒ Object
Add a description to the next namespace or function.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/grape/dsl/desc.rb', line 48 def desc(description, = {}, &config_block) if block_given? config_class = desc_container config_class.configure do description description end config_class.configure(&config_block) unless .empty? warn '[DEPRECATION] Passing a options hash and a block to `desc` is deprecated. Move all hash options to block.' end = config_class.settings else = .merge(description: description) end namespace_setting :description, route_setting :description, end |
#desc_container ⇒ Object
Returns an object which configures itself via an instance-context DSL.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/grape/dsl/desc.rb', line 86 def desc_container Module.new do include Grape::Util::StrictHashConfiguration.module( :summary, :description, :detail, :params, :entity, :http_codes, :named, :headers, :hidden, :deprecated, :is_array, :nickname, :produces, :consumes, :tags ) def config_context.success(*args) entity(*args) end def config_context.failure(*args) http_codes(*args) end end end |
#description_field(field, value = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/grape/dsl/desc.rb', line 69 def description_field(field, value = nil) if value description = route_setting(:description) description ||= route_setting(:description, {}) description[field] = value else description = route_setting(:description) description[field] if description end end |
#unset_description_field(field) ⇒ Object
80 81 82 83 |
# File 'lib/grape/dsl/desc.rb', line 80 def unset_description_field(field) description = route_setting(:description) description.delete(field) if description end |