Class: Loom::Pattern::ExpandingReference
- Inherits:
-
Object
- Object
- Loom::Pattern::ExpandingReference
- Defined in:
- lib/loom/pattern/expanding_reference.rb
Defined Under Namespace
Classes: Matcher
Constant Summary collapse
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
TODO: Ensure ExpandingReference and Reference stay in sync.
-
#pattern ⇒ Object
readonly
TODO: Ensure ExpandingReference and Reference stay in sync.
-
#reference_slugs ⇒ Object
readonly
TODO: Ensure ExpandingReference and Reference stay in sync.
-
#slug ⇒ Object
readonly
TODO: Ensure ExpandingReference and Reference stay in sync.
-
#source_file ⇒ Object
readonly
TODO: Ensure ExpandingReference and Reference stay in sync.
Instance Method Summary collapse
- #expand_slugs ⇒ Object
-
#initialize(slug, pattern, reference_set) ⇒ ExpandingReference
constructor
A new instance of ExpandingReference.
Constructor Details
#initialize(slug, pattern, reference_set) ⇒ ExpandingReference
Returns a new instance of ExpandingReference.
15 16 17 18 19 20 21 22 23 24 |
# 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. @desc = pattern.description @pattern end |
Instance Attribute Details
#desc ⇒ Object (readonly)
TODO: Ensure ExpandingReference and Reference stay in sync. Maybe create an inheritance hierarchy.
10 11 12 |
# File 'lib/loom/pattern/expanding_reference.rb', line 10 def desc @desc end |
#pattern ⇒ Object (readonly)
TODO: Ensure ExpandingReference and Reference stay in sync. Maybe create an inheritance hierarchy.
10 11 12 |
# File 'lib/loom/pattern/expanding_reference.rb', line 10 def pattern @pattern end |
#reference_slugs ⇒ Object (readonly)
TODO: Ensure ExpandingReference and Reference stay in sync. Maybe create an inheritance hierarchy.
10 11 12 |
# File 'lib/loom/pattern/expanding_reference.rb', line 10 def reference_slugs @reference_slugs end |
#slug ⇒ Object (readonly)
TODO: Ensure ExpandingReference and Reference stay in sync. Maybe create an inheritance hierarchy.
10 11 12 |
# File 'lib/loom/pattern/expanding_reference.rb', line 10 def slug @slug end |
#source_file ⇒ Object (readonly)
TODO: Ensure ExpandingReference and Reference stay in sync. Maybe create an inheritance hierarchy.
10 11 12 |
# File 'lib/loom/pattern/expanding_reference.rb', line 10 def source_file @source_file end |
Instance Method Details
#expand_slugs ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/loom/pattern/expanding_reference.rb', line 26 def # O(MN) :( = @reference_slugs.flat_map do |my_slug| matcher = Matcher.get_matcher(my_slug) @reference_set.slugs.select { |your_slug| matcher.match? your_slug } end.uniq Loom.log.debug3(self) { "Loom::Pattern::ExpandingReference@reference_slugs+: #{@reference_slugs.join(",")}"} Loom.log.debug3(self) { "Loom::Pattern::ExpandingReference+expanded_slugs+: #{.join(",")}"} = .map { |s| @reference_set[s] } .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}] => #{.join(",")}"} end |