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

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

Overview

Stores information about a HasTree::CacheAncestry concern.

Since:

  • 0.5.0

Instance Attribute Summary

Attributes inherited from Concern::Metadata

#name, #properties

Instance Method Summary collapse

Methods inherited from Concern::Metadata

#characterize, #initialize, #relation_key, #relation_key?

Constructor Details

This class inherits a constructor from Mongoid::SleepingKingStudios::Concern::Metadata

Instance Method Details

#children_nameSymbol

The name of the children relation for the tree.

Returns:

  • (Symbol)

    The relation name.

Since:

  • 0.5.0



13
14
15
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 13

def children_name
  self[:children_name] || :children
end

#children_name?Boolean

Returns True if a custom children relation name is set; otherwise false.

Returns:

  • (Boolean)

    True if a custom children relation name is set; otherwise false.

Since:

  • 0.5.0



19
20
21
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 19

def children_name?
  !!self[:children_name]
end

#foreign_keySymbol

The name of the field used to store ancestor references. If no foreign key is set, uses the relation name and the field name to generate a key.

Returns:

  • (Symbol)

    The field name.

Since:

  • 0.5.0



28
29
30
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 28

def foreign_key
  self[:foreign_key] || :"#{relation_name.to_s.singularize}_ids"
end

#parent_foreign_keySymbol

The name of the field used to store the tree’s parent relation.

Returns:

  • (Symbol)

    The method name.

Since:

  • 0.5.0



35
36
37
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 35

def parent_foreign_key
  :"#{parent_name}_id"
end

#parent_foreign_key_writerSymbol

The writer for the tree’s parent relation id.

Returns:

  • (Symbol)

    The method name.

Since:

  • 0.5.0



42
43
44
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 42

def parent_foreign_key_writer
  :"#{parent_name}_id="
end

#parent_nameSymbol

The name of the parent relation for the tree.

Returns:

  • (Symbol)

    The relation name.

Since:

  • 0.5.0



49
50
51
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 49

def parent_name
  self[:parent_name] || :parent
end

#parent_name?Boolean

Returns True if a custom children relation name is set; otherwise false.

Returns:

  • (Boolean)

    True if a custom children relation name is set; otherwise false.

Since:

  • 0.5.0



55
56
57
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 55

def parent_name?
  !!self[:parent_name]
end

#parent_writerSymbol

The writer for the tree’s parent relation.

Returns:

  • (Symbol)

    The method name.

Since:

  • 0.5.0



62
63
64
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 62

def parent_writer
  :"#{parent_name}="
end

#relation_nameSymbol

The name of the tree’s ancestors method. If no relation name is set, defaults to :ancestors.

Returns:

  • (Symbol)

    The relation name.

Since:

  • 0.5.0



70
71
72
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 70

def relation_name
  fetch(:relation_name, :ancestors)
end

#relation_name?Boolean

Returns True if a custom relation name is set; otherwise false.

Returns:

  • (Boolean)

    True if a custom relation name is set; otherwise false.

Since:

  • 0.5.0



76
77
78
# File 'lib/mongoid/sleeping_king_studios/has_tree/cache_ancestry/metadata.rb', line 76

def relation_name?
  !!self[:relation_name]
end