Class: Aikido::Zen::Payload

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/aikido/zen/payload.rb', line 7

def path
  @path
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/aikido/zen/payload.rb', line 7

def source
  @source
end

#valueObject (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_jsonObject



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

#inspectObject



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