class Mongoid::SleepingKingStudios::HasTree::Metadata
Stores information about a HasTree
concern.
Public Class Methods
new(name, properties = {})
click to toggle source
@param [Symbol, String] name The name of the concern or relation. @param [Hash] properties The properties of the concern or relation.
Calls superclass method
Mongoid::SleepingKingStudios::Concern::Metadata::new
# 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
Public Instance Methods
cache_ancestry()
click to toggle source
The metadata associated with the :cache_ancestry option.
@return [Metadata] The :cache_ancestry metadata.
# File lib/mongoid/sleeping_king_studios/has_tree/metadata.rb, line 32 def cache_ancestry self[:cache_ancestry] end
cache_ancestry?()
click to toggle source
@return [Boolean] True if the :cache_ancestry option is selected;
otherwise false.
# File lib/mongoid/sleeping_king_studios/has_tree/metadata.rb, line 38 def cache_ancestry? !!self[:cache_ancestry] end
children()
click to toggle source
The metadata associated with the children
relation.
@return [Metadata] The children metadata.
# File lib/mongoid/sleeping_king_studios/has_tree/metadata.rb, line 45 def children self[:children] end
foreign_key()
click to toggle source
The foreign key for the parent relation.
@return [Symbol] The foreign key.
# File lib/mongoid/sleeping_king_studios/has_tree/metadata.rb, line 52 def foreign_key self[:foreign_key] || :"#{parent.relation_name}_id" end
parent()
click to toggle source
The metadata associated with the parent
relation.
@return [Metadata] The parent metadata.
# File lib/mongoid/sleeping_king_studios/has_tree/metadata.rb, line 59 def parent self[:parent] end