Class: Watobo::SIDCache
- Inherits:
-
Object
- Object
- Watobo::SIDCache
- Defined in:
- lib/watobo/core/sid_cache.rb
Overview
:nodoc: all
Instance Attribute Summary collapse
-
#sids ⇒ Object
readonly
Returns the value of attribute sids.
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize ⇒ SIDCache
constructor
A new instance of SIDCache.
- #update_request(request) ⇒ Object
- #update_sids(site, response) ⇒ Object
Constructor Details
#initialize ⇒ SIDCache
Returns a new instance of SIDCache.
20 21 22 23 |
# File 'lib/watobo/core/sid_cache.rb', line 20 def initialize() @cache_lock = Mutex.new @sids = {} end |
Instance Attribute Details
#sids ⇒ Object (readonly)
Returns the value of attribute sids.
9 10 11 |
# File 'lib/watobo/core/sid_cache.rb', line 9 def sids @sids end |
Class Method Details
Instance Method Details
#clear ⇒ Object
16 17 18 |
# File 'lib/watobo/core/sid_cache.rb', line 16 def clear @sids = {} end |
#update_request(request) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/watobo/core/sid_cache.rb', line 61 def update_request(request) @cache_lock.synchronize do if @sids.has_key?(request.site) valid_sids = @sids[request.site] puts "* found sid for site: #{request.site}" if $DEBUG request.map!{ |line| res = line self.class.patterns.each do |pat| begin if line =~ /#{pat}/i then next if $~.length < 3 sid_key = Regexp.quote($1.upcase) old_value = $2 if valid_sids.has_key?(sid_key) then if not old_value =~ /#{@sids[request.site][sid_key]}/ then # sid value has changed and needs update Watobo.print_debug("#{self} update session", "#{old_value} - #{@sids[request.site][sid_key]}") if $DEBUG unless old_value.empty? res = line.gsub!(/#{Regexp.quote(old_value)}/, valid_sids[sid_key]) end if not res then puts "!!!could not update sid (#{sid_key})"; end end end end rescue => bang puts bang puts bang.backtrace if $DEBUG # puts @cache.to_yaml end end res } end end end |
#update_sids(site, response) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/watobo/core/sid_cache.rb', line 34 def update_sids(site, response) begin #site = request.site @cache_lock.synchronize do response.each do |line| # puts line self.class.patterns.each do |pat| if line =~ /#{pat}/i then sid_key = Regexp.quote($1.upcase) sid_value = $2 puts "#{self} GOT NEW SID (#{sid_key}): #{sid_value}" @sids[site] ||= Hash.new @sids[site][sid_key] = sid_value end end end end rescue => bang puts bang puts bang.backtrace if $DEBUG end end |