Class: Threshold::Thresholds
- Inherits:
-
Object
- Object
- Threshold::Thresholds
- Extended by:
- Forwardable
- Defined in:
- lib/threshold/thresholds.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#readonly ⇒ Object
Returns the value of attribute readonly.
Instance Method Summary collapse
-
#&(an0ther) ⇒ Object
Returns a new Threshold Object.
-
#+(an0ther) ⇒ Object
+ (concat) Returns a new Threshold Object.
-
#-(an0ther) ⇒ Object
-
(Difference) Returns a new Threshold Object.
-
-
#event_filters(&blk) ⇒ Object
Returns a new Threshold Object with just event_filters.
-
#flush ⇒ Object
Write changes to the file.
-
#initialize(thresholds = []) ⇒ Thresholds
constructor
A new instance of Thresholds.
-
#loadfile ⇒ Object
Append in the thresholds.conf file to current collection.
-
#loadfile! ⇒ Object
Clears current collection and Read in the thresholds.conf file.
-
#rate_filters(&blk) ⇒ Object
Returns a new Threshold Object with just rate_filters.
-
#reject(&blk) ⇒ Object
Returns a new Threshold Object.
-
#reverse ⇒ Object
Returns a new Threshold Object.
-
#select(&blk) ⇒ Object
Returns a new Threshold Object.
-
#shuffle ⇒ Object
Returns a new Threshold Object.
-
#sort ⇒ Object
Returns a new Threshold Object.
-
#stored_hash ⇒ Object
The calculated hash of the threshold.conf file at load time.
-
#suppressions(&blk) ⇒ Object
Returns a new Threshold Object with just suppressions.
- #to_a ⇒ Object
-
#to_s(skip = false) ⇒ Object
Pass (true) to_s to skip the printing of InternalObjects.comment.
-
#uniq(&blk) ⇒ Object
Uniques by default to printable output Returns a new Threshold Object.
-
#valid? ⇒ Boolean
Check if all objects in the Threshold Instance report .valid?.
-
#|(an0ther) ⇒ Object
| (intersect) Returns a new Threshold Object.
Constructor Details
#initialize(thresholds = []) ⇒ Thresholds
Returns a new instance of Thresholds.
17 18 19 |
# File 'lib/threshold/thresholds.rb', line 17 def initialize(thresholds = []) @thresholds = thresholds end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
13 14 15 |
# File 'lib/threshold/thresholds.rb', line 13 def file @file end |
#readonly ⇒ Object
Returns the value of attribute readonly.
13 14 15 |
# File 'lib/threshold/thresholds.rb', line 13 def readonly @readonly end |
Instance Method Details
#&(an0ther) ⇒ Object
Returns a new Threshold Object
162 163 164 |
# File 'lib/threshold/thresholds.rb', line 162 def &(an0ther) Thresholds.new(@thresholds & an0ther.to_a) end |
#+(an0ther) ⇒ Object
+ (concat) Returns a new Threshold Object
151 152 153 |
# File 'lib/threshold/thresholds.rb', line 151 def +(an0ther) Thresholds.new(@thresholds + an0ther.to_a) end |
#-(an0ther) ⇒ Object
-
(Difference)
Returns a new Threshold Object
168 169 170 |
# File 'lib/threshold/thresholds.rb', line 168 def -(an0ther) Thresholds.new(@thresholds - an0ther.to_a) end |
#event_filters(&blk) ⇒ Object
Returns a new Threshold Object with just event_filters
182 183 184 185 186 187 188 |
# File 'lib/threshold/thresholds.rb', line 182 def event_filters(&blk) if block_given? self.event_filters.select(&blk) else Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::EventFilter"}) end end |
#flush ⇒ Object
Write changes to the file
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/threshold/thresholds.rb', line 22 def flush begin valid_existing_file?(@file) raise ReadOnlyThresholdsFile if @readonly hash = current_hash file = File.open(@file, 'w+') raise ThresholdAtomicLockFailure, 'The @file state/hash changed before we could flush the file' unless stored_hash == hash file.write self.sort.to_s file.close rescue NonExistantThresholdFile raise ReadOnlyThresholdsFile if @readonly file = File.open(@file, 'w') file.write self.sort.to_s file.close end stored_hash=current_hash return true end |
#loadfile ⇒ Object
Append in the thresholds.conf file to current collection
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/threshold/thresholds.rb', line 50 def loadfile valid_existing_file?(@file) results = Threshold::Parser.new(@file) @stored_hash= results.filehash #puts stored_hash results.caps.each do |result| builder = Threshold::Builder.new(result) self << builder.build end end |
#loadfile! ⇒ Object
Clears current collection and Read in the thresholds.conf file
44 45 46 47 |
# File 'lib/threshold/thresholds.rb', line 44 def loadfile! @thresholds.clear loadfile end |
#rate_filters(&blk) ⇒ Object
Returns a new Threshold Object with just rate_filters
191 192 193 194 195 196 197 |
# File 'lib/threshold/thresholds.rb', line 191 def rate_filters(&blk) if block_given? self.rate_filters.select(&blk) else Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::RateFilter"}) end end |
#reject(&blk) ⇒ Object
Returns a new Threshold Object
119 120 121 122 123 124 125 |
# File 'lib/threshold/thresholds.rb', line 119 def reject(&blk) if block_given? Thresholds.new(@thresholds.reject(&blk)) else Thresholds.new(@thresholds.reject) end end |
#reverse ⇒ Object
Returns a new Threshold Object
109 110 111 |
# File 'lib/threshold/thresholds.rb', line 109 def reverse Thresholds.new(@thresholds.reverse) end |
#select(&blk) ⇒ Object
Returns a new Threshold Object
128 129 130 131 132 133 134 |
# File 'lib/threshold/thresholds.rb', line 128 def select(&blk) if block_given? Thresholds.new(@thresholds.select(&blk)) else Thresholds.new(@thresholds.select) end end |
#shuffle ⇒ Object
Returns a new Threshold Object
114 115 116 |
# File 'lib/threshold/thresholds.rb', line 114 def shuffle Thresholds.new(@thresholds.shuffle) end |
#sort ⇒ Object
Returns a new Threshold Object
104 105 106 |
# File 'lib/threshold/thresholds.rb', line 104 def sort Thresholds.new(@thresholds.sort) end |
#stored_hash ⇒ Object
The calculated hash of the threshold.conf file at load time.
92 93 94 |
# File 'lib/threshold/thresholds.rb', line 92 def stored_hash @stored_hash end |
#suppressions(&blk) ⇒ Object
Returns a new Threshold Object with just suppressions
173 174 175 176 177 178 179 |
# File 'lib/threshold/thresholds.rb', line 173 def suppressions(&blk) if block_given? self.suppressions.select(&blk) else Thresholds.new(@thresholds.select{|t| t.class.to_s == "Threshold::Suppression"}) end end |
#to_a ⇒ Object
95 96 97 |
# File 'lib/threshold/thresholds.rb', line 95 def to_a @thresholds end |
#to_s(skip = false) ⇒ Object
Pass (true) to_s to skip the printing of InternalObjects.comment
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/threshold/thresholds.rb', line 80 def to_s(skip = false) output = "" raise InvalidThresholdsObject, "Container object has unknown objects" unless valid? self.each do |threshold| output << threshold.to_s(skip) + "\n" end return output end |
#uniq(&blk) ⇒ Object
Uniques by default to printable output Returns a new Threshold Object
138 139 140 141 142 143 144 |
# File 'lib/threshold/thresholds.rb', line 138 def uniq(&blk) if block_given? Thresholds.new(@thresholds.uniq(&blk)) else Thresholds.new(@thresholds.uniq{ |lineitem| lineitem.to_s(true) }) end end |
#valid? ⇒ Boolean
Check if all objects in the Threshold Instance report .valid?
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/threshold/thresholds.rb', line 64 def valid? begin self.each do |threshold| if threshold.respond_to?(:valid?) return false unless threshold.valid? else raise InvalidThresholdsObject, "Container object has unknown objects" end end return true rescue InvalidThresholdsObject return false end end |
#|(an0ther) ⇒ Object
| (intersect) Returns a new Threshold Object
157 158 159 |
# File 'lib/threshold/thresholds.rb', line 157 def |(an0ther) Thresholds.new(@thresholds | an0ther.to_a) end |