class Loom::Pattern::ExpandingReference
Constants
- RecursiveExpansionError
Attributes
desc[R]
TODO: Ensure ExpandingReference
and Reference
stay in sync. Maybe create an inheritance hierarchy.
pattern[R]
TODO: Ensure ExpandingReference
and Reference
stay in sync. Maybe create an inheritance hierarchy.
reference_slugs[R]
TODO: Ensure ExpandingReference
and Reference
stay in sync. Maybe create an inheritance hierarchy.
slug[R]
TODO: Ensure ExpandingReference
and Reference
stay in sync. Maybe create an inheritance hierarchy.
source_file[R]
TODO: Ensure ExpandingReference
and Reference
stay in sync. Maybe create an inheritance hierarchy.
Public Class Methods
new(slug, pattern, reference_set)
click to toggle source
@param slug [String]: flattened colon separated slug name @param pattern [Loom::Pattern::Pattern]: a pattern responding to expanded_slugs
# File lib/loom/pattern/expanding_reference.rb, line 15 def initialize(slug, pattern, reference_set) @slug = slug @reference_set = reference_set # TODO: Hmm... I tried to abstract the "weave" keyword from the # "ExpandingReference" concept... but it leaked through. Think the # `pattern.kind` based method name over. @reference_slugs = pattern.weave.expanded_slugs @desc = pattern.description @pattern end
Public Instance Methods
expand_slugs()
click to toggle source
# File lib/loom/pattern/expanding_reference.rb, line 26 def expand_slugs slug_matchers = @reference_slugs.map do |s| Matcher.get_matcher(s) end # O(MN) :( expanded_slugs = @reference_slugs.flat_map do |s| @reference_set.slugs.select { |s| slug_matchers.any? { |m| m.match?(s) } } end.uniq Loom.log.debug3(self) { "Loom::Pattern::ExpandingReference@reference_slugs+: #{@reference_slugs.join(",")}"} Loom.log.debug3(self) { "Loom::Pattern::ExpandingReference+expanded_slugs+: #{expanded_slugs.join(",")}"} expanded_refs = expanded_slugs.map { |s| @reference_set[s] } expanded_refs.each do |r| if r.is_a? ExpandingReference Loom.log.error "recursive expansion for pattern[#{r.slug}] in weave[#{@slug}], i.e. only patterns are allowed in weaves" raise RecursiveExpansionError, @slug end end Loom.log.info { "expanded slug[#{@slug}] => #{expanded_slugs.join(",")}"} expanded_slugs end