Class: Toxiproxy::Toxic
- Inherits:
-
Object
- Object
- Toxiproxy::Toxic
- Defined in:
- lib/toxiproxy/toxic.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
-
#toxicity ⇒ Object
Returns the value of attribute toxicity.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json ⇒ Object
- #destroy ⇒ Object
-
#initialize(attrs) ⇒ Toxic
constructor
A new instance of Toxic.
- #save ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Toxic
Returns a new instance of Toxic.
6 7 8 9 10 11 12 13 14 |
# File 'lib/toxiproxy/toxic.rb', line 6 def initialize(attrs) raise "Toxic type is required" unless attrs[:type] @type = attrs[:type] @stream = attrs[:stream] || 'downstream' @name = attrs[:name] || "#{@type}_#{@stream}" @proxy = attrs[:proxy] @toxicity = attrs[:toxicity] || 1.0 @attributes = attrs[:attributes] || {} end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/toxiproxy/toxic.rb', line 4 def attributes @attributes end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/toxiproxy/toxic.rb', line 3 def name @name end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
3 4 5 |
# File 'lib/toxiproxy/toxic.rb', line 3 def proxy @proxy end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
3 4 5 |
# File 'lib/toxiproxy/toxic.rb', line 3 def stream @stream end |
#toxicity ⇒ Object
Returns the value of attribute toxicity.
4 5 6 |
# File 'lib/toxiproxy/toxic.rb', line 4 def toxicity @toxicity end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/toxiproxy/toxic.rb', line 3 def type @type end |
Instance Method Details
#as_json ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/toxiproxy/toxic.rb', line 39 def as_json { name: name, type: type, stream: stream, toxicity: toxicity, attributes: attributes, }.to_json end |
#destroy ⇒ Object
32 33 34 35 36 37 |
# File 'lib/toxiproxy/toxic.rb', line 32 def destroy request = Net::HTTP::Delete.new("/proxies/#{proxy.name}/toxics/#{name}") response = Toxiproxy.http_request(request) Toxiproxy.assert_response(response) self end |
#save ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/toxiproxy/toxic.rb', line 16 def save request = Net::HTTP::Post.new("/proxies/#{proxy.name}/toxics") request["Content-Type"] = "application/json" request.body = as_json response = Toxiproxy.http_request(request) Toxiproxy.assert_response(response) json = JSON.parse(response.body) @attributes = json['attributes'] @toxicity = json['toxicity'] self end |