Class: Webgen::ItemTracker::Nodes
- Inherits:
-
Object
- Object
- Webgen::ItemTracker::Nodes
- Defined in:
- lib/webgen/item_tracker/nodes.rb
Overview
This class is used to track changes to a (nested) list of nodes.
An item for this tracker has to consist of the following fields:
-
An array consisting of [class/module name, method name] or a string/symbol specifying a method name
-
Options argument (use an array or hash for multiple arguments)
-
Either :content or :meta_info, depending on whether the content or the meta info of the found nodes should be tracked.
The list of nodes is retrieved in one of two ways, depending on the type of the first field:
-
If it is a string/symbol, it specifies the name of a method on this class. This method has to take the options hash as the only parameter.
-
If it is an array, the array has to contain a class/module name and a method name. The method is invoked with the current Webgen::Website object as first and the options hash as second parameter.
For example, consider the following statement:
website.ext.item_tracker.add(some_node, :nodes,
["MyModule::MyClass", "my_method"], {:some => 'options'}, :content)
The method will be invoked like this for retrieving the nodes:
MyModule::MyClass.my_method(website, {:some => 'options'})
Instance Method Summary collapse
-
#initialize(website) ⇒ Nodes
constructor
:nodoc:.
-
#item_changed?(iid, old_data) ⇒ Boolean
:nodoc:.
-
#item_data(method_name, options, type) ⇒ Object
:nodoc:.
-
#item_description(iid, data) ⇒ Object
:nodoc:.
-
#item_id(method_name, options, type) ⇒ Object
:nodoc:.
-
#node_finder_option_set(options) ⇒ Object
Use Webgen::NodeFinder to generate a (nested) list of nodes.
-
#referenced_nodes(iid, alcn_list) ⇒ Object
:nodoc:.
Constructor Details
#initialize(website) ⇒ Nodes
:nodoc:
38 39 40 |
# File 'lib/webgen/item_tracker/nodes.rb', line 38 def initialize(website) #:nodoc: @website = website end |
Instance Method Details
#item_changed?(iid, old_data) ⇒ Boolean
:nodoc:
50 51 52 53 54 55 |
# File 'lib/webgen/item_tracker/nodes.rb', line 50 def item_changed?(iid, old_data) #:nodoc: method_name, , type = *iid nodes = node_list(method_name, ) old_data != nodes_to_alcn(nodes) || nodes.flatten.any? {|n| type == :content ? @website.ext.item_tracker.node_changed?(n) : @website.ext.item_tracker.item_changed?(:node_meta_info, n)} end |
#item_data(method_name, options, type) ⇒ Object
:nodoc:
46 47 48 |
# File 'lib/webgen/item_tracker/nodes.rb', line 46 def item_data(method_name, , type) #:nodoc: nodes_to_alcn(node_list(method_name, )) end |
#item_description(iid, data) ⇒ Object
:nodoc:
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/webgen/item_tracker/nodes.rb', line 61 def item_description(iid, data) #:nodoc: method, _, type = *iid str = (type == :content ? "Content" : "Meta info") << " from these nodes" str << " (result of #{[method].flatten.join('.')}):" data_mapper = lambda do |item| if item.kind_of?(Array) [item[0], item[1].map(&data_mapper).map {|inner| [inner].flatten.map {|l| " #{l}"}}] else item end end [str] + data.map(&data_mapper).flatten end |
#item_id(method_name, options, type) ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/webgen/item_tracker/nodes.rb', line 42 def item_id(method_name, , type) #:nodoc: [method_name, , type] end |
#node_finder_option_set(options) ⇒ Object
Use Webgen::NodeFinder to generate a (nested) list of nodes. The options hash has to contain two keys:
-
:opts → the node finder option set
-
:ref_alcn → the alcn of the reference node
81 82 83 |
# File 'lib/webgen/item_tracker/nodes.rb', line 81 def node_finder_option_set() @website.ext.node_finder.find([:opts], @website.tree[[:ref_alcn]]) end |
#referenced_nodes(iid, alcn_list) ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/webgen/item_tracker/nodes.rb', line 57 def referenced_nodes(iid, alcn_list) #:nodoc: alcn_list.flatten end |