Class: Exoteric::Counter
- Inherits:
-
Object
- Object
- Exoteric::Counter
- Defined in:
- lib/exoteric/counter.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #count(*counters) ⇒ Object
-
#initialize(options = {}) ⇒ Counter
constructor
A new instance of Counter.
Constructor Details
#initialize(options = {}) ⇒ Counter
Returns a new instance of Counter.
19 20 21 22 |
# File 'lib/exoteric/counter.rb', line 19 def initialize( = {}) @url, @options = [:url], raise ArgumentError, "Site url not specified" if @url.to_s.empty? end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/exoteric/counter.rb', line 8 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
8 9 10 |
# File 'lib/exoteric/counter.rb', line 8 def url @url end |
Class Method Details
.<<(counter) ⇒ Object
10 11 12 13 |
# File 'lib/exoteric/counter.rb', line 10 def self.<<(counter) send :include, counter counters << counter.id end |
.counters ⇒ Object
15 16 17 |
# File 'lib/exoteric/counter.rb', line 15 def self.counters @counters ||= [] end |
Instance Method Details
#count(*counters) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/exoteric/counter.rb', line 24 def count(*counters) if counters.size == 0 || counters.first == :all counters = self.class.counters end res = {} sem = Mutex.new threads = [] counters.each do |name| threads << Thread.new do sem.synchronize { res[name] = send("#{name}_count") } end end Timeout.timeout(10) do threads.each(&:join) end rescue Timeout::Error # nothing to do... ensure return res.clone end |