Class: Jinx::ReferenceVisitor
- Defined in:
- lib/jinx/resource/reference_visitor.rb
Overview
A ReferenceVisitor traverses reference attributes.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Visitor
Instance Method Summary collapse
-
#attributes_to_visit(obj) ⇒ Propertied::Filter
private
The attributes to visit.
-
#initialize(opts = nil) {|obj| ... } ⇒ ReferenceVisitor
constructor
Creates a new ReferenceVisitor on domain reference attributes.
Methods inherited from Visitor
#clear, #current, #cyclic_nodes, #depth_first?, #filter, #from, #node_children, #root, #sync, #to_enum, #visit, #visit_children, #visit_node_and_children, #visit_recursive, #visit_root, #visited?
Constructor Details
#initialize(opts = nil) {|obj| ... } ⇒ ReferenceVisitor
Creates a new ReferenceVisitor on domain reference attributes.
The required selector block given to this initializer determines which attributes to visit. The references to visit next thus consist of the current domain object’s selector attributes’ values. If the :filter option is set, then the given filter block is applied to each selected attribute reference to determine which domain objects will be visited.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jinx/resource/reference_visitor.rb', line 24 def initialize(opts=nil, &selector) raise ArgumentError.new("Reference visitor missing domain reference selector") unless block_given? # the property selector @selector = selector # the reference filter @filter = Options.get(:filter, opts) # Initialize the Visitor with a reference enumerator which selects the reference # attributes and applies the optional filter if necessary. @ref_enums = {} super do |obj| # the reference property filter ras = attributes_to_visit(obj) if ras then logger.debug { "#{qp} visiting #{obj} attributes #{ras.pp_s(:single_line)}..." } if @verbose # an enumerator on the reference properties enum = ReferenceEnumerator.new(obj, ras.properties) # If there is a reference filter, then apply it to the enum references. @filter ? enum.filter(&@filter) : enum end end end |
Instance Method Details
#attributes_to_visit(obj) ⇒ Propertied::Filter (private)
Returns the attributes to visit.
50 51 52 |
# File 'lib/jinx/resource/reference_visitor.rb', line 50 def attributes_to_visit(obj) @selector.call(obj) end |