Class: Jekyll::RpLogs::TagImplicationHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/rp_logs/rp_tag_implication_handler.rb

Defined Under Namespace

Classes: TagImplicationError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TagImplicationHandler

Extract global settings from the config file.



11
12
13
14
15
# File 'lib/jekyll/rp_logs/rp_tag_implication_handler.rb', line 11

def initialize(config)
  @tag_implications = (config["tag_implications"] || {}).freeze
  @tag_aliases = (config["tag_aliases"] || {}).freeze
  validate_tag_rules
end

Instance Attribute Details

#tag_aliasesObject (readonly)

Returns the value of attribute tag_aliases.



7
8
9
# File 'lib/jekyll/rp_logs/rp_tag_implication_handler.rb', line 7

def tag_aliases
  @tag_aliases
end

#tag_implicationsObject (readonly)

Returns the value of attribute tag_implications.



7
8
9
# File 'lib/jekyll/rp_logs/rp_tag_implication_handler.rb', line 7

def tag_implications
  @tag_implications
end

Instance Method Details

#update_tags(tag_set, verbose: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/jekyll/rp_logs/rp_tag_implication_handler.rb', line 17

def update_tags(tag_set, verbose: false)
  removed_tags = Set.new
  loop do
    previous_tags = tag_set.clone
    cyclical = catch :cyclical_tags do
      implicate_tags(tag_set, removed_tags, verbose)
      alias_tags(tag_set, removed_tags)
      false
    end
    if cyclical
      fail_with "The tag #{cyclical[1]} (from #{cyclical[0]} => #{cyclical[1]}) has been removed before. There is a cycle in the tag aliases and implications."
    end
    # Break when there is no change in tags.
    return tag_set if tag_set == previous_tags
  end
end