Class: ActionSpec::Doc::Request
- Inherits:
-
Object
- Object
- ActionSpec::Doc::Request
- Defined in:
- lib/action_spec/doc/endpoint.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_media_types ⇒ Object
readonly
Returns the value of attribute body_media_types.
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#scope_options ⇒ Object
readonly
Returns the value of attribute scope_options.
Instance Method Summary collapse
- #add_body(media_type, field) ⇒ Object
- #add_param(location_name, field) ⇒ Object
- #body_required? ⇒ Boolean
- #copy ⇒ Object
- #custom_validation? ⇒ Boolean
- #custom_validation_locations ⇒ Object
-
#initialize ⇒ Request
constructor
A new instance of Request.
- #location(name) ⇒ Object
- #register_scope(name, compact: nil, compact_blank: nil) ⇒ Object
- #replace_with(other) ⇒ Object
- #require_body! ⇒ Object
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/action_spec/doc/endpoint.rb', line 43 def initialize @header = Location.new(:header) @path = Location.new(:path) @query = Location.new(:query) @cookie = Location.new(:cookie) @body = Location.new(:body) @body_media_types = {} @scope_options = ActiveSupport::HashWithIndifferentAccess.new @body_required = false end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def body @body end |
#body_media_types ⇒ Object (readonly)
Returns the value of attribute body_media_types.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def body_media_types @body_media_types end |
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def @cookie end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def header @header end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def query @query end |
#scope_options ⇒ Object (readonly)
Returns the value of attribute scope_options.
41 42 43 |
# File 'lib/action_spec/doc/endpoint.rb', line 41 def @scope_options end |
Instance Method Details
#add_body(media_type, field) ⇒ Object
63 64 65 66 67 |
# File 'lib/action_spec/doc/endpoint.rb', line 63 def add_body(media_type, field) body.add(field) (@body_media_types[media_type.to_sym] ||= Location.new(media_type.to_sym)).add(field.copy) clear_custom_validation_cache! end |
#add_param(location_name, field) ⇒ Object
58 59 60 61 |
# File 'lib/action_spec/doc/endpoint.rb', line 58 def add_param(location_name, field) location(location_name).add(field) clear_custom_validation_cache! end |
#body_required? ⇒ Boolean
83 84 85 |
# File 'lib/action_spec/doc/endpoint.rb', line 83 def body_required? @body_required end |
#copy ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/action_spec/doc/endpoint.rb', line 99 def copy self.class.new.tap do |request| request.instance_variable_set(:@header, header.copy) request.instance_variable_set(:@path, path.copy) request.instance_variable_set(:@query, query.copy) request.instance_variable_set(:@cookie, .copy) request.instance_variable_set(:@body, body.copy) request.instance_variable_set( :@body_media_types, body_media_types.transform_values(&:copy) ) request.instance_variable_set(:@scope_options, .deep_dup) request.instance_variable_set(:@body_required, body_required?) end end |
#custom_validation? ⇒ Boolean
115 116 117 |
# File 'lib/action_spec/doc/endpoint.rb', line 115 def custom_validation? custom_validation_locations.any? end |
#custom_validation_locations ⇒ Object
119 120 121 |
# File 'lib/action_spec/doc/endpoint.rb', line 119 def custom_validation_locations @custom_validation_locations ||= [header, path, query, , body].select(&:custom_validation?).freeze end |
#location(name) ⇒ Object
54 55 56 |
# File 'lib/action_spec/doc/endpoint.rb', line 54 def location(name) public_send(name) end |
#register_scope(name, compact: nil, compact_blank: nil) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/action_spec/doc/endpoint.rb', line 69 def register_scope(name, compact: nil, compact_blank: nil) key = name.to_sym @scope_options[key] = .fetch(key, {}).merge( { compact:, compact_blank: }.compact ) end |
#replace_with(other) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/action_spec/doc/endpoint.rb', line 87 def replace_with(other) @header = other.header @path = other.path @query = other.query @cookie = other. @body = other.body @body_media_types = other.body_media_types @scope_options = other. @body_required = other.body_required? clear_custom_validation_cache! end |
#require_body! ⇒ Object
79 80 81 |
# File 'lib/action_spec/doc/endpoint.rb', line 79 def require_body! @body_required = true end |