module Docks::Tags

Public Class Methods

<<(tag) click to toggle source
# File lib/docks/tags.rb, line 36
def self.<<(tag)
  register(tag)
end
base_tag_name(tag) click to toggle source
# File lib/docks/tags.rb, line 7
def self.base_tag_name(tag)
  tag = tag.instance.name if tag.instance_of?(Class)
  tag = tag.name if tag.kind_of?(Base)
  tag = tag.to_sym

  found = @synonyms[tag]
  return found if found
end
has_tag?(tag) click to toggle source
# File lib/docks/tags.rb, line 67
def self.has_tag?(tag)
  !tag_for(tag).nil?
end
join_synonymous_tags(hash) click to toggle source
# File lib/docks/tags.rb, line 40
def self.join_synonymous_tags(hash)
  final_hash = {}
  hash.each do |tag, value|
    tag = tag.to_s.singularize.to_sym
    base_tag = @synonyms[tag]

    next if base_tag.nil?

    if final_hash[base_tag].nil?
      # No previous result for this tag or its synonyms. This effectively
      # includes all non-multiple-allowed tags.
      begin
        final_hash[base_tag] = value.clone
      rescue TypeError
        final_hash[base_tag] = value
      end
    else
      # All tags that could have previously-included synonym tags must be
      # multiple-allowed tags. All multiple-allowed tags have new arrays
      # for each declared tag.
      final_hash[base_tag].concat(value)
    end
  end

  final_hash
end
register(tag) click to toggle source
# File lib/docks/tags.rb, line 20
def self.register(tag)
  tag = tag.instance
  tag.setup_post_processors

  return false if tag.name.nil?
  tag_name = tag.name.to_sym
  @tags[tag_name] = tag

  [tag_name, tag.synonyms].flatten.each do |synonym|
    @synonyms[synonym.to_sym] = tag_name
    @synonyms[synonym.to_s.pluralize.to_sym] = tag_name if tag.multiple_allowed?
  end

  true
end
register_bundled_tags() click to toggle source
# File lib/docks/tags.rb, line 16
def self.register_bundled_tags
  bundled_tags.each { |tag| register(tag) }
end
supported_parseable_tags() click to toggle source
# File lib/docks/tags.rb, line 75
def self.supported_parseable_tags
  supported_tags.select { |tag| tag_for(tag).parseable? }
end
supported_tags() click to toggle source
# File lib/docks/tags.rb, line 71
def self.supported_tags
  @synonyms.keys
end
tag_for(tag) click to toggle source
# File lib/docks/tags.rb, line 3
def self.tag_for(tag)
  @tags[base_tag_name(tag)]
end

Private Class Methods

bundled_tags() click to toggle source
# File lib/docks/tags.rb, line 82
def self.bundled_tags
  if @bundled_tags.nil?
    bundled = constants.select do |const|
      klass = const_get(const)
      Class === klass && !(klass.eql?(Base))
    end

    @bundled_tags = bundled.map { |const| const_get(const) }
  end

  @bundled_tags
end
clean() click to toggle source
# File lib/docks/tags.rb, line 95
def self.clean
  @tags = {}
  @synonyms = {}
  @bundled_tags = nil
end