Method: Jinx::MatchVisitor#match_reference
- Defined in:
- lib/jinx/resource/match_visitor.rb
#match_reference(source, target, attribute) ⇒ {Resource => Resource} (private)
Matches the given source and target attribute references. The match is performed by this visitor’s matcher.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/jinx/resource/match_visitor.rb', line 131 def match_reference(source, target, attribute) srcs = source.send(attribute).to_enum tgts = target.send(attribute).to_enum # the match targets mtchd_tgts = Set.new # capture the matched targets and the the unmatched sources unmtchd_srcs = srcs.reject do |src| # the prior match, if any tgt = match_for(src) mtchd_tgts << tgt if tgt end # the unmatched targets unmtchd_tgts = tgts.difference(mtchd_tgts) logger.debug { "#{qp} matching #{unmtchd_tgts.qp}..." } if @verbose and not unmtchd_tgts.empty? # match the residual targets and sources rsd_mtchs = @matcher.match(unmtchd_srcs, unmtchd_tgts, source, attribute) # add residual matches rsd_mtchs.each { |src, tgt| add_match(src, tgt) } logger.debug { "#{qp} matched #{rsd_mtchs.qp}..." } if @verbose and not rsd_mtchs.empty? # The source => target match hash. # If there is a copier, then copy each unmatched source. matches = srcs.to_compact_hash { |src| match_for(src) or copy_unmatched(src) } matches end |