Sha256: 608480c71fc91bdec203fe76aa0b5654dd971575dd5cbbe09cb24aaed1c75cf3

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 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, nil]
    #   Tracks changes to the whole meta information of the node, i.e. if any meta information value
    #   changes, a change is detected.
    #
    # [node, 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) # first case
    #   website.ext.item_tracker.add(some_node, :node_meta_info, my_node, 'title') # second case
    #
    class NodeMetaInfo

      CONTENT_MODIFICATION_KEY = 'modified_at'

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

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

      def item_data(alcn, key = nil) #:nodoc:
        mi = @website.tree[alcn].meta_info
        if key.nil? && mi['modified_at_in_dest_path']
          mi
        elsif key.nil?
          (mi = mi.dup; mi.delete(CONTENT_MODIFICATION_KEY); mi)
        else
          mi[key].dup
        end
      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

7 entries across 7 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.7.2 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.7.1 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.7.0 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.6.0 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.5.2 lib/webgen/item_tracker/node_meta_info.rb
webgen-1.5.1 lib/webgen/item_tracker/node_meta_info.rb