Class: ActionSpec::Doc::Response
- Inherits:
-
Object
- Object
- ActionSpec::Doc::Response
- Defined in:
- lib/action_spec/doc/endpoint.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#media_types ⇒ Object
readonly
Returns the value of attribute media_types.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #copy ⇒ Object
-
#initialize(code:, description:, media_type:, schema: nil, example: nil, examples: nil, options:) ⇒ Response
constructor
A new instance of Response.
- #merge(other) ⇒ Object
Constructor Details
#initialize(code:, description:, media_type:, schema: nil, example: nil, examples: nil, options:) ⇒ Response
Returns a new instance of Response.
185 186 187 188 189 190 191 |
# File 'lib/action_spec/doc/endpoint.rb', line 185 def initialize(code:, description:, media_type:, schema: nil, example: nil, examples: nil, options:) @code = code.to_s @description = description @media_types = ActiveSupport::OrderedHash.new @options = .deep_dup merge_media_type!(media_type || :json, schema:, example:, examples:, initialize: true) end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
183 184 185 |
# File 'lib/action_spec/doc/endpoint.rb', line 183 def code @code end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
183 184 185 |
# File 'lib/action_spec/doc/endpoint.rb', line 183 def description @description end |
#media_types ⇒ Object (readonly)
Returns the value of attribute media_types.
183 184 185 |
# File 'lib/action_spec/doc/endpoint.rb', line 183 def media_types @media_types end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
183 184 185 |
# File 'lib/action_spec/doc/endpoint.rb', line 183 def @options end |
Instance Method Details
#copy ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/action_spec/doc/endpoint.rb', line 203 def copy self.class.new( code:, description:, media_type: nil, schema: nil, example: nil, examples: nil, options: .deep_dup ).tap do |response| response.instance_variable_set( :@media_types, media_types.each_with_object(ActiveSupport::OrderedHash.new) do |(media_type, content), hash| hash[media_type] = copy_content(content) end ) end end |
#merge(other) ⇒ Object
193 194 195 196 197 198 199 200 201 |
# File 'lib/action_spec/doc/endpoint.rb', line 193 def merge(other) copy.tap do |merged| merged.instance_variable_set(:@description, other.description.presence || description) merged.instance_variable_set(:@options, .deep_dup.merge(other..deep_dup)) other.media_types.each do |media_type, content| merged.send(:merge_media_type!, media_type, **merged.send(:copy_content, content)) end end end |