class Docks::Tags::IncludeWith

Public Class Methods

new() click to toggle source
# File lib/docks/tags/include_with_tag.rb, line 4
def initialize
  @name = :include_with
  @multiline = false
  @multiple_allowed = true
end

Public Instance Methods

process(symbol) click to toggle source
# File lib/docks/tags/include_with_tag.rb, line 10
def process(symbol)
  symbol.update(@name) do |include_with|
    Array(include_with).map { |with| split_on_commas_spaces_and_pipes(with) }.flatten
  end
end
setup_post_processors() click to toggle source
# File lib/docks/tags/include_with_tag.rb, line 16
def setup_post_processors
  after_each_pattern(:late) do |pattern|
    components = pattern.components
    components.each { |component| find_and_associate_inclusion(component, components) }
  end
end

Private Instance Methods

find_and_associate_inclusion(component, components) click to toggle source
# File lib/docks/tags/include_with_tag.rb, line 25
def find_and_associate_inclusion(component, components)
  include_withs = component.fetch(:include_with, [])
  unless include_withs.empty?
    components.each do |other|
      next unless include_withs.include?(other.name)
      other.included_symbols ||= []
      other.included_symbols << component
    end
  end

  component.variations do |variation|
    include_withs = variation.fetch(:include_with, [])
    next if include_withs.empty?
    components.each do |other|
      next unless include_withs.include?(other.name)
      other.included_symbols ||= []
      other.included_symbols << variation
    end
  end

  component.subcomponents { |subcomponent| find_and_associate_inclusion(subcomponent, components) }
end