Class: Jinx::CopyVisitor

Inherits:
MergeVisitor show all
Defined in:
lib/jinx/resource/copy_visitor.rb

Overview

A CopyVisitor copies a domain object’s visitable attributes transitive closure.

Constant Summary

Constants inherited from MatchVisitor

MatchVisitor::DEF_MATCHER

Instance Attribute Summary

Attributes inherited from MatchVisitor

#matches

Attributes inherited from Visitor

#lineage, #options, #visited

Instance Method Summary collapse

Methods inherited from MergeVisitor

#merge

Methods inherited from MatchVisitor

#add_match, #copy_unmatched, #identifier_match, #match_for, #match_for_visited, #match_reference, #match_references, #visit_matched

Methods inherited from ReferenceVisitor

#attributes_to_visit

Methods inherited from Visitor

#clear, #current, #cyclic_nodes, #depth_first?, #filter, #from, #node_children, #root, #sync, #to_enum, #visit_children, #visit_node_and_children, #visit_recursive, #visit_root, #visited?

Constructor Details

#initialize(opts = nil) {|obj| ... } ⇒ CopyVisitor

Creates a new CopyVisitor with the options described in MergeVisitor#initialize. The default :copier option is Resource#copy.

Parameters:

  • opts (Hash) (defaults to: nil)

    a customizable set of options

  • opts (Hash) (defaults to: nil)

    a customizable set of options

  • opts (Symbol, {Symbol => Object}) (defaults to: nil)

    the visit options

Options Hash (opts):

  • :mergeable (Proc)

    the mergeable domain attribute selector

  • :matcher (Proc)

    the match block

  • :copier (Proc)

    the unmatched source copy block

Yields:

  • (obj)

    returns the AttributeEnumerator of attributes to visit next from the current domain object

Yield Parameters:

  • source (Resource)

    the matched source object



15
16
17
18
19
20
21
# File 'lib/jinx/resource/copy_visitor.rb', line 15

def initialize(opts=nil)
  opts = Options.to_hash(opts)
  opts[:copier] ||= Proc.new { |src| src.copy }
  # no match forces a copy
  opts[:matcher] = self
  super
end

Instance Method Details

#match(sources, targets, from = nil, property = nil) ⇒ Object



32
33
34
# File 'lib/jinx/resource/copy_visitor.rb', line 32

def match(sources, targets, from=nil, property=nil)
  Hash::EMPTY_HASH
end

#visit(source) ⇒ Resource

Copies the given source domain object’s reference graph.

Parameters:

  • source (Resource)

    the domain object to merge from

  • target (Resource)

    the domain object to merge into

Returns:



27
28
29
30
# File 'lib/jinx/resource/copy_visitor.rb', line 27

def visit(source)
  target = @copier.call(source)
  super(source, target)
end