Class: Mongoid::SleepingKingStudios::HasTree::Metadata

Inherits:
Concern::Metadata show all
Defined in:
lib/mongoid/sleeping_king_studios/has_tree/metadata.rb

Overview

Stores information about a HasTree concern.

Since:

  • 0.2.0

Instance Attribute Summary

Attributes inherited from Concern::Metadata

#name, #properties

Instance Method Summary collapse

Methods inherited from Concern::Metadata

#characterize, #relation_key, #relation_key?

Constructor Details

#initialize(name, properties = {}) ⇒ Metadata

Returns a new instance of Metadata

Since:

  • 0.2.0


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_ancestryMetadata

The metadata associated with the :cache_ancestry option.

Since:

  • 0.2.0


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.

Since:

  • 0.2.0


38
39
40
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 38

def cache_ancestry?
  !!self[:cache_ancestry]
end

#childrenMetadata

The metadata associated with the #children relation.

Since:

  • 0.2.0


45
46
47
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 45

def children
  self[:children]
end

#foreign_keySymbol

The foreign key for the parent relation.

Since:

  • 0.2.0


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

#parentMetadata

The metadata associated with the #parent relation.

Since:

  • 0.2.0


59
60
61
# File 'lib/mongoid/sleeping_king_studios/has_tree/metadata.rb', line 59

def parent
  self[:parent]
end