class HtmlSlicer::CachedStuff

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.

Attributes

changed[RW]
hexdigest[R]
resizing[R]
slicing[R]
time[RW]
version[R]

Public Class Methods

new(text = nil) click to toggle source
# 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

Public Instance Methods

changed?() click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 59
def changed?
  @changed
end
hexdigest_for=(text) click to toggle source
# 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
resizing=(object) click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 37
def resizing=(object)
  case object
  when HtmlSlicer::Mappers::Resizing, nil then
    @changed = true unless object.try(:options).try(:hexdigest) == @slicing.try(:options).try(:hexdigest)
    @resizing = object
  else
    raise(TypeError, "HtmlSlicer::Mappers::Resizing or nil expected, '#{object.class}' passed")
  end
end
slicing=(object) click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 27
def slicing=(object)
  case object
  when HtmlSlicer::Mappers::Slicing, nil then
    @changed = true unless object.try(:options).try(:hexdigest) == @slicing.try(:options).try(:hexdigest)
    @slicing = object
  else
    raise(TypeError, "HtmlSlicer::Mappers::Slicing or nil expected, '#{object.class}' passed")
  end
end
to_dump() click to toggle source

Serialize self, using Marshal and Base64 encoding

# 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) click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 51
def valid_resizing_options?(options)
  options.try(:hexdigest) == @resizing.try(:options).try(:hexdigest)
end
valid_slicing_options?(options) click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 55
def valid_slicing_options?(options)
  options.try(:hexdigest) == @slicing.try(:options).try(:hexdigest)
end
valid_text?(text) click to toggle source
# File lib/html_slicer/cached_stuff.rb, line 47
def valid_text?(text)
  Digest::SHA1.hexdigest(text) == @hexdigest
end