Sha256: 4c58ae983f4f122079c03a42f3aad3d11d626ae83a15f2a129f349f8d8fee0e5

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

# -*- encoding: utf-8 -*-

require 'webgen/item_tracker'

module Webgen
  class ItemTracker

    # This class is used to track changes to a node's meta information.
    #
    # Depending on what should be tracked, one needs to provide the following item:
    #
    # [node_alcn, nil]
    #   Tracks changes to the whole meta information of the node, i.e. if any meta information value
    #   changes, a change is detected.
    #
    # [node_alcn, key]
    #   Tracks changes to a specific meta information key of the node.
    #
    # Here are some examples:
    #
    #   website.ext.item_tracker.add(some_node, :node_meta_info, my_node.alcn) # first case
    #   website.ext.item_tracker.add(some_node, :node_meta_info, my_node.alcn, 'title') # second case
    #
    class NodeMetaInfo

      CONTENT_MODIFICATION_KEY = 'modified_at'

      def initialize(website) #:nodoc:
        @website = website
      end

      def item_id(alcn, key = nil) #:nodoc:
        [alcn, key]
      end

      def item_data(alcn, key = nil) #:nodoc:
        mi = @website.tree[alcn].meta_info
        key.nil? ? (mi = mi.dup; mi.delete(CONTENT_MODIFICATION_KEY); mi) : mi[key].dup
      end

      def item_changed?(iid, old_data) #:nodoc:
        alcn, key = *iid
        @website.tree[alcn].nil? || item_data(alcn, key) != old_data
      end

      def referenced_nodes(iid, mi) #:nodoc:
        [iid.first]
      end

      def item_description(iid, data) #:nodoc:
        alcn, key = *iid
        (key.nil? ? "Any meta info from <#{alcn}>" : "Meta info key '#{key}' from <#{alcn}>")
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webgen-1.0.0.beta2 lib/webgen/item_tracker/node_meta_info.rb