Class: Toxiproxy::ToxicCollection
- Inherits:
-
Object
- Object
- Toxiproxy::ToxicCollection
- Extended by:
- Forwardable
- Defined in:
- lib/toxiproxy/toxic_collection.rb
Instance Attribute Summary collapse
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
-
#toxics ⇒ Object
Returns the value of attribute toxics.
Instance Method Summary collapse
- #apply(&block) ⇒ Object
- #downstream(type, attrs = {}) ⇒ Object (also: #toxic, #toxicate)
-
#initialize(proxies) ⇒ ToxicCollection
constructor
A new instance of ToxicCollection.
- #upstream(type, attrs = {}) ⇒ Object
Constructor Details
#initialize(proxies) ⇒ ToxicCollection
Returns a new instance of ToxicCollection.
10 11 12 13 |
# File 'lib/toxiproxy/toxic_collection.rb', line 10 def initialize(proxies) @proxies = proxies @toxics = [] end |
Instance Attribute Details
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
6 7 8 |
# File 'lib/toxiproxy/toxic_collection.rb', line 6 def proxies @proxies end |
#toxics ⇒ Object
Returns the value of attribute toxics.
5 6 7 |
# File 'lib/toxiproxy/toxic_collection.rb', line 5 def toxics @toxics end |
Instance Method Details
#apply(&block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/toxiproxy/toxic_collection.rb', line 15 def apply(&block) names = toxics.group_by { |t| [t.name, t.proxy.name] } dups = names.values.select { |toxics| toxics.length > 1 } if !dups.empty? raise ArgumentError, "There are two toxics with the name #{dups.first[0]} for proxy #{dups.first[1]}, please override the default name (<type>_<direction>)" end begin @toxics.each(&:save) yield ensure @toxics.each(&:destroy) end end |
#downstream(type, attrs = {}) ⇒ Object Also known as: toxic, toxicate
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/toxiproxy/toxic_collection.rb', line 44 def downstream(type, attrs = {}) proxies.each do |proxy| toxics << Toxic.new( name: attrs.delete('name') || attrs.delete(:name), type: type, proxy: proxy, stream: :downstream, toxicity: attrs.delete('toxicitiy') || attrs.delete(:toxicity), attributes: attrs ) end self end |
#upstream(type, attrs = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/toxiproxy/toxic_collection.rb', line 30 def upstream(type, attrs = {}) proxies.each do |proxy| toxics << Toxic.new( name: attrs.delete('name') || attrs.delete(:name), type: type, proxy: proxy, stream: :upstream, toxicity: attrs.delete('toxicitiy') || attrs.delete(:toxicity), attributes: attrs ) end self end |