Class: CanTango::Config::Categories
- Inherits:
-
Registry::Hash
- Object
- Registry::Base
- Registry::Hash
- CanTango::Config::Categories
- Includes:
- Singleton
- Defined in:
- lib/cantango/config/categories.rb
Instance Attribute Summary
Attributes included from Registry::Base::InstanceMethods
#available, #default, #registered
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 included from Registry::Hash::InstanceMethods
#<<, #[]=, #clean!, #default, #default!, #default=, #register, #registered, #registered?, #registered_names, #registered_value?, #registered_values, #types, #types=, #unregister, #value_methods, #value_types
Methods included from Registry::Base::InstanceMethods
#clean!, #default!, #register, #registered?, #reset!, #types, #types=, #valid?
Instance Method Details
#[](label) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/cantango/config/categories.rb', line 6 def [] label models = super return [] unless models.kind_of?(Array) # 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/config/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/config/categories.rb', line 13 def category label, &block cat = CanTango::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/config/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/config/categories.rb', line 20 def has_any? subject, &block found = registered.any? {|cat, subjects| subjects.include? subject } yield if found && block found end |