Class: Pho::Etags
- Inherits:
-
Object
- Object
- Pho::Etags
- Defined in:
- lib/pho/etags.rb
Overview
Simple mechanism for managing etags
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#saved ⇒ Object
readonly
Returns the value of attribute saved.
Instance Method Summary collapse
- #add(uri, tag) ⇒ Object
- #add_from_response(uri, response) ⇒ Object
- #get(uri) ⇒ Object
- #has_tag?(uri) ⇒ Boolean
-
#initialize(file = nil) ⇒ Etags
constructor
A new instance of Etags.
- #save(other = nil) ⇒ Object
Constructor Details
#initialize(file = nil) ⇒ Etags
Returns a new instance of Etags.
11 12 13 14 15 16 17 18 |
# File 'lib/pho/etags.rb', line 11 def initialize(file = nil) @file = file @saved = true @tags = Hash.new if @file != nil @tags = YAML::load(@file)[0] end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/pho/etags.rb', line 9 def file @file end |
#saved ⇒ Object (readonly)
Returns the value of attribute saved.
9 10 11 |
# File 'lib/pho/etags.rb', line 9 def saved @saved end |
Instance Method Details
#add(uri, tag) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/pho/etags.rb', line 34 def add(uri, tag) if (uri != nil && tag != nil) @tags[uri] = tag @saved = false end end |
#add_from_response(uri, response) ⇒ Object
41 42 43 |
# File 'lib/pho/etags.rb', line 41 def add_from_response(uri, response) add(uri, response.header["ETag"][0]) end |
#get(uri) ⇒ Object
45 46 47 |
# File 'lib/pho/etags.rb', line 45 def get(uri) return @tags[uri] end |
#has_tag?(uri) ⇒ Boolean
49 50 51 |
# File 'lib/pho/etags.rb', line 49 def has_tag?(uri) return @tags.has_key?(uri) end |
#save(other = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pho/etags.rb', line 20 def save(other=nil) if (other != nil) other.write( @tags.to_yaml() ) return else if (!saved && @file != nil ) @file.write( @tags.to_yaml() ) @file.close end end end |