Class: Alki::Execution::OverlayMap

Inherits:
Object
  • Object
show all
Defined in:
lib/alki/execution/overlay_map.rb

Instance Method Summary collapse

Constructor Details

#initialize(overlays = {}) ⇒ OverlayMap

Returns a new instance of OverlayMap.



4
5
6
# File 'lib/alki/execution/overlay_map.rb', line 4

def initialize(overlays = {})
  @overlays = overlays
end

Instance Method Details

#add(path, *overlays) ⇒ Object



26
27
28
29
# File 'lib/alki/execution/overlay_map.rb', line 26

def add(path,*overlays)
  @overlays[path] ||= []
  @overlays[path].push *overlays
end

#index(key, tags) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/alki/execution/overlay_map.rb', line 8

def index(key,tags)
  self.class.new.tap do |new_overlays|
    @overlays.each do |target,overlays|
      target = target.dup
      if target.size == 1 && target[0].to_s.start_with?('%')
        if tags
          tag = target[0].to_s[1..-1].to_sym
          tags.elements_in(tag).each do |path|
            new_overlays.add path, *overlays
          end
        end
      elsif target.empty? || target.shift == key.to_sym
        new_overlays.add target, *overlays
      end
    end
  end
end

#overlaysObject



31
32
33
34
# File 'lib/alki/execution/overlay_map.rb', line 31

def overlays
  overlays = @overlays[[]] || []
  overlays.sort_by(&:order).group_by(&:type)
end