Class: Aikido::Zen::Payload
- Inherits:
-
Object
- Object
- Aikido::Zen::Payload
- Defined in:
- lib/aikido/zen/payload.rb
Overview
An individual user input in a request, which may come from different sources (query string, body, cookies, etc).
Constant Summary collapse
- UNKNOWN_PAYLOAD =
Payload.new("unknown", "unknown", "unknown")
- SOURCE_SERIALIZATIONS =
{ query: "query", body: "body", header: "headers", cookie: "cookies", route: "routeParams", graphql: "graphql", xml: "xml", subdomain: "subdomains" }
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#value ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json ⇒ Object
-
#initialize(value, source, path) ⇒ Payload
constructor
A new instance of Payload.
- #inspect ⇒ Object
Constructor Details
#initialize(value, source, path) ⇒ Payload
Returns a new instance of Payload.
9 10 11 12 13 |
# File 'lib/aikido/zen/payload.rb', line 9 def initialize(value, source, path) @value = value @source = source @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/aikido/zen/payload.rb', line 7 def path @path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/aikido/zen/payload.rb', line 7 def source @source end |
#value ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute value.
7 8 9 |
# File 'lib/aikido/zen/payload.rb', line 7 def value @value end |
Instance Method Details
#==(other) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/aikido/zen/payload.rb', line 19 def ==(other) other.is_a?(Payload) && other.value == value && other.source == source && other.path == path end |
#as_json ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/aikido/zen/payload.rb', line 26 def as_json { payload: value.to_s, source: SOURCE_SERIALIZATIONS[source], path: path.to_s } end |
#inspect ⇒ Object
45 46 47 48 |
# File 'lib/aikido/zen/payload.rb', line 45 def inspect val = (value.to_s.size > 128) ? value[0..125] + "..." : value "#<Aikido::Zen::Payload #{source}(#{path}) #{val.inspect}>" end |