Class: HtmlSlicer::CachedStuff
- Inherits:
-
Object
- Object
- HtmlSlicer::CachedStuff
- Defined in:
- lib/html_slicer/cached_stuff.rb
Overview
Object to be serialized and dumped as cache storage. Include resizing
and slicing
objects, and original text’s hexdigest hash value to provide authenticity. During the runtime object is used as an maps
accessor too.
Instance Attribute Summary collapse
-
#changed ⇒ Object
Returns the value of attribute changed.
-
#hexdigest ⇒ Object
readonly
Returns the value of attribute hexdigest.
-
#resizing ⇒ Object
Returns the value of attribute resizing.
-
#slicing ⇒ Object
Returns the value of attribute slicing.
-
#time ⇒ Object
Returns the value of attribute time.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #hexdigest_for=(text) ⇒ Object
-
#initialize(text = nil) ⇒ CachedStuff
constructor
A new instance of CachedStuff.
-
#to_dump ⇒ Object
Serialize self, using Marshal and Base64 encoding.
- #valid_resizing_options?(options) ⇒ Boolean
- #valid_slicing_options?(options) ⇒ Boolean
- #valid_text?(text) ⇒ Boolean
Constructor Details
#initialize(text = nil) ⇒ CachedStuff
Returns a new instance of CachedStuff.
12 13 14 15 16 |
# File 'lib/html_slicer/cached_stuff.rb', line 12 def initialize(text = nil) @version = HtmlSlicer::VERSION @changed = false self.hexdigest_for = text if text end |
Instance Attribute Details
#changed ⇒ Object
Returns the value of attribute changed.
10 11 12 |
# File 'lib/html_slicer/cached_stuff.rb', line 10 def changed @changed end |
#hexdigest ⇒ Object (readonly)
Returns the value of attribute hexdigest.
9 10 11 |
# File 'lib/html_slicer/cached_stuff.rb', line 9 def hexdigest @hexdigest end |
#resizing ⇒ Object
Returns the value of attribute resizing.
9 10 11 |
# File 'lib/html_slicer/cached_stuff.rb', line 9 def resizing @resizing end |
#slicing ⇒ Object
Returns the value of attribute slicing.
9 10 11 |
# File 'lib/html_slicer/cached_stuff.rb', line 9 def slicing @slicing end |
#time ⇒ Object
Returns the value of attribute time.
10 11 12 |
# File 'lib/html_slicer/cached_stuff.rb', line 10 def time @time end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/html_slicer/cached_stuff.rb', line 9 def version @version end |
Instance Method Details
#changed? ⇒ Boolean
59 60 61 |
# File 'lib/html_slicer/cached_stuff.rb', line 59 def changed? @changed end |
#hexdigest_for=(text) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/html_slicer/cached_stuff.rb', line 18 def hexdigest_for=(text) hex = Digest::SHA1.hexdigest(text) unless hex == @hexdigest @changed = true @hexdigest = hex end hex end |
#to_dump ⇒ Object
Serialize self, using Marshal and Base64 encoding
64 65 66 67 |
# File 'lib/html_slicer/cached_stuff.rb', line 64 def to_dump @time = Time.now Base64.encode64(Marshal.dump(self)) end |
#valid_resizing_options?(options) ⇒ Boolean
51 52 53 |
# File 'lib/html_slicer/cached_stuff.rb', line 51 def () .try(:hexdigest) == @resizing.try(:options).try(:hexdigest) end |
#valid_slicing_options?(options) ⇒ Boolean
55 56 57 |
# File 'lib/html_slicer/cached_stuff.rb', line 55 def () .try(:hexdigest) == @slicing.try(:options).try(:hexdigest) end |
#valid_text?(text) ⇒ Boolean
47 48 49 |
# File 'lib/html_slicer/cached_stuff.rb', line 47 def valid_text?(text) Digest::SHA1.hexdigest(text) == @hexdigest end |