Class: Mongoid::SleepingKingStudios::HasTree::Metadata
- Inherits:
-
Concern::Metadata
- Object
- Hash
- Concern::Metadata
- Mongoid::SleepingKingStudios::HasTree::Metadata
- Defined in:
- lib/mongoid/sleeping_king_studios/has_tree/metadata.rb
Overview
Stores information about a HasTree concern.
Instance Attribute Summary
Attributes inherited from Concern::Metadata
Instance Method Summary collapse
-
#cache_ancestry ⇒ Metadata
The metadata associated with the :cache_ancestry option.
-
#cache_ancestry? ⇒ Boolean
True if the :cache_ancestry option is selected; otherwise false.
-
#children ⇒ Metadata
The metadata associated with the #children relation.
-
#foreign_key ⇒ Symbol
The foreign key for the parent relation.
-
#initialize(name, properties = {}) ⇒ Metadata
constructor
A new instance of Metadata.
-
#parent ⇒ Metadata
The metadata associated with the #parent relation.
Methods inherited from Concern::Metadata
#characterize, #relation_key, #relation_key?
Constructor Details
#initialize(name, properties = {}) ⇒ Metadata
Returns a new instance of Metadata.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 14 def initialize name, properties = {} super self[:parent] = characterize :parent, properties.fetch(:parent, {}), HasTree::Parent::Metadata self[:children] = characterize :children, properties.fetch(:children, {}), HasTree::Children::Metadata if properties.fetch(:cache_ancestry, false) properties[:cache_ancestry] = {} unless Hash === properties[:cache_ancestry] properties[:cache_ancestry][:children_name] = children.relation_name properties[:cache_ancestry][:parent_name] = parent.relation_name self[:cache_ancestry] = characterize :cache_ancestry, properties[:cache_ancestry], HasTree::CacheAncestry::Metadata end # unless end |
Instance Method Details
#cache_ancestry ⇒ Metadata
The metadata associated with the :cache_ancestry option.
32 33 34 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 32 def cache_ancestry self[:cache_ancestry] end |
#cache_ancestry? ⇒ Boolean
Returns True if the :cache_ancestry option is selected; otherwise false.
38 39 40 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 38 def cache_ancestry? !!self[:cache_ancestry] end |
#children ⇒ Metadata
The metadata associated with the #children relation.
45 46 47 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 45 def children self[:children] end |
#foreign_key ⇒ Symbol
The foreign key for the parent relation.
52 53 54 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 52 def foreign_key self[:foreign_key] || :"#{parent.relation_name}_id" end |
#parent ⇒ Metadata
The metadata associated with the #parent relation.
59 60 61 |
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 59 def parent self[:parent] end |