Class: CamaleonCms::TermTaxonomy
- Inherits:
-
CamaleonRecord
- Object
- ActiveRecord::Base
- CamaleonRecord
- CamaleonCms::TermTaxonomy
- Extended by:
- NormalizeAttrs
- Includes:
- ContentShortcodeGate, 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
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 67 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 33 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
9 10 11 12 13 14 15 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 9 def self.inherited(subclass) super subclass.class_eval do include CamaleonCms::CommonRelationships end end |
.polymorphic_name ⇒ Object
29 30 31 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 29 def self.polymorphic_name name.demodulize end |
.sti_name ⇒ Object
25 26 27 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 25 def self.sti_name name.demodulize.underscore end |
Instance Method Details
#children ⇒ Object
return all children taxonomy sample: sub categories of a category
92 93 94 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 92 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
97 98 99 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 97 def CamaleonCms::NavMenuItem.where(url: id, kind: taxonomy) end |
#skip_slug_validation? ⇒ Boolean
permit to skip slug validations for children models, like menu items
102 103 104 |
# File 'app/models/camaleon_cms/term_taxonomy.rb', line 102 def skip_slug_validation? false end |