Sha256: 19ba24008b6edef5bf704af0599b9a4fc8c0125b3f5d3ef4c99667c9fe480d22
Contents?: true
Size: 1.07 KB
Versions: 8
Compression:
Stored size: 1.07 KB
Contents
module CanTango class Configuration class Categories < Registry::Hash include Singleton def [] label models = super raise "Category '#{label}' either not exists or invalid!" if !models.kind_of?(Array) models end def category label, &block cat = Category.new self[label] yield cat if block cat end # test if a any of the categories contain the subject def has_any? subject, &block found = registered.any? {|cat, subjects| subjects.include? subject } yield if found && block found end # find the category of a subject if such a category exists def category_names_of_subject subject, &block categories_of_subject(subject).keys end # find the category of a subject if such a category exists def categories_of_subject subject, &block found_categories = registered.select do |cat, subjects| subjects.include? subject.to_s end found_categories.empty? ? {} : found_categories end end end end
Version data entries
8 entries across 8 versions & 1 rubygems