Class: CanTango::Configuration::Categories
- Inherits:
-
HashRegistry
- Object
- Registry
- HashRegistry
- CanTango::Configuration::Categories
- Includes:
- Singleton
- Defined in:
- lib/cantango/configuration/categories.rb
Defined Under Namespace
Classes: Category
Instance Attribute Summary
Attributes inherited from Registry
Instance Method Summary collapse
- #[](label) ⇒ Object
-
#categories_of_subject(subject, &block) ⇒ Object
find the category of a subject if such a category exists.
- #category(label) {|cat| ... } ⇒ Object
-
#category_names_of_subject(subject, &block) ⇒ Object
find the category of a subject if such a category exists.
-
#has_any?(subject, &block) ⇒ Boolean
test if a any of the categories contain the subject.
Methods inherited from HashRegistry
#<<, #[]=, #clean!, #clear!, #default, #default!, #default=, #register, #registered, #types, #types=
Methods inherited from Registry
#clean!, #default!, #register, #registered?, #types, #types=
Instance Method Details
#[](label) ⇒ Object
7 8 9 10 11 |
# File 'lib/cantango/configuration/categories.rb', line 7 def [] label models = super raise "Category '#{label}' either not exists or invalid!" if !models.kind_of?(Array) models end |
#categories_of_subject(subject, &block) ⇒ Object
find the category of a subject if such a category exists
32 33 34 35 36 37 |
# File 'lib/cantango/configuration/categories.rb', line 32 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 |
#category(label) {|cat| ... } ⇒ Object
13 14 15 16 17 |
# File 'lib/cantango/configuration/categories.rb', line 13 def category label, &block cat = Category.new self[label] yield cat if block cat end |
#category_names_of_subject(subject, &block) ⇒ Object
find the category of a subject if such a category exists
27 28 29 |
# File 'lib/cantango/configuration/categories.rb', line 27 def category_names_of_subject subject, &block categories_of_subject(subject).keys end |
#has_any?(subject, &block) ⇒ Boolean
test if a any of the categories contain the subject
20 21 22 23 24 |
# File 'lib/cantango/configuration/categories.rb', line 20 def has_any? subject, &block found = registered.any? {|cat, subjects| subjects.include? subject } yield if found && block found end |