Class: CamaleonCms::TermTaxonomy
- Inherits:
-
CamaleonRecord
- Object
- ActiveRecord::Base
- CamaleonRecord
- CamaleonCms::TermTaxonomy
- Extended by:
- NormalizeAttrs
- Includes:
- CustomFieldsRead, Metas
- Defined in:
- app/models/camaleon_cms/term_taxonomy.rb
Direct Known Subclasses
Category, NavMenu, NavMenuItem, Plugin, PostTag, PostType, Site, Theme, UserRole, Widget::Main, Widget::Sidebar
Constant Summary
Constants inherited from CamaleonRecord
CamaleonRecord::TRANSLATION_TAG_HIDE_MAP, CamaleonRecord::TRANSLATION_TAG_HIDE_REGEX, CamaleonRecord::TRANSLATION_TAG_HIDE_SENTINELS, CamaleonRecord::TRANSLATION_TAG_RESTORE_MAP, CamaleonRecord::TRANSLATION_TAG_RESTORE_REGEX
Class Method Summary collapse
- .find_sti_class(type_name) ⇒ Object
- .inherited(subclass) ⇒ Object
- .polymorphic_name ⇒ Object
- .sti_name ⇒ Object
Instance Method Summary collapse
-
#children ⇒ Object
return all children taxonomy sample: sub categories of a category.
-
#in_nav_menu_items ⇒ Object
return all menu items in which this taxonomy was assigned.
-
#skip_slug_validation? ⇒ Boolean
permit to skip slug validations for children models, like menu items.
Methods included from NormalizeAttrs
Methods included from CustomFieldsRead
#add_custom_field_group, #add_custom_field_to_default_group, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_grouped, #get_fields_object, #get_user_field_groups, #save_field_value, #set_field_value, #set_field_values, #update_field_value
Methods included from Metas
#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_option, #set_options
Methods inherited from CamaleonRecord
#ability, #cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, cama_sanitize_translatable, #cama_set_cache, #can?, #current_site, #current_user, polymorphic_class_for, #reset_ability
Class Method Details
.find_sti_class(type_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 32 def self.find_sti_class(type_name) # Handle explicit exceptions where database string doesn't match namespacing layout case type_name.to_s when 'widget' return CamaleonCms::Widget::Main when 'sidebar' return CamaleonCms::Widget::Sidebar end # Standard conversion for "site" -> "CamaleonCms::Site" # or "nav_menu_item" -> "CamaleonCms::NavMenuItem" klass = begin "CamaleonCms::#{type_name.camelize}".constantize rescue NameError nil end # The ancestry guard keeps a value like "meta" from instantiating an unrelated # CamaleonCms class against the term_taxonomy table. return klass if klass && klass <= base_class # Runtime scan across loaded taxonomy models. found = CamaleonCms::TermTaxonomy.descendants.find { |k| k.sti_name == type_name.to_s } return found if found # `super` resolves fully-qualified external classes (plugin STI outside the CamaleonCms # namespace) and enforces ancestry — the scan above only sees classes already loaded, so # without this an unloaded plugin taxonomy silently degraded to the base class. Same # fallback PostDefault.find_sti_class keeps. Values it cannot place load as the base class, # as every row did before native STI. begin super rescue ActiveRecord::SubclassNotFound base_class end end |
.inherited(subclass) ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 8 def self.inherited(subclass) super subclass.class_eval do include CamaleonCms::CommonRelationships end end |
.polymorphic_name ⇒ Object
28 29 30 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 28 def self.polymorphic_name name.demodulize end |
.sti_name ⇒ Object
24 25 26 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 24 def self.sti_name name.demodulize.underscore end |
Instance Method Details
#children ⇒ Object
return all children taxonomy sample: sub categories of a category
86 87 88 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 86 def children CamaleonCms::TermTaxonomy.where("#{CamaleonCms::TermTaxonomy.table_name}.parent_id = ?", id) end |
#in_nav_menu_items ⇒ Object
return all menu items in which this taxonomy was assigned
91 92 93 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 91 def CamaleonCms::NavMenuItem.where(url: id, kind: taxonomy) end |
#skip_slug_validation? ⇒ Boolean
permit to skip slug validations for children models, like menu items
96 97 98 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 96 def skip_slug_validation? false end |