Class: Mongoid::SleepingKingStudios::Concern::Metadata
- Inherits:
-
Hash
- Object
- Hash
- Mongoid::SleepingKingStudios::Concern::Metadata
- Defined in:
- lib/mongoid/sleeping_king_studios/concern/metadata.rb
Overview
Stores information about a given concern or relation. By default, stored in the Document class’s ::relations attribute. Concerns may subclass Metadata to add further keys and/or functionality.
Direct Known Subclasses
HasTree::CacheAncestry::Metadata, HasTree::Children::Metadata, HasTree::Metadata, HasTree::Parent::Metadata, Orderable::Metadata, Sluggable::Metadata
Instance Attribute Summary collapse
-
#name ⇒ Symbol
readonly
The name of the concern or relation.
-
#properties ⇒ Hash
readonly
The unmodified properties hash that was passed into the constructor.
Instance Method Summary collapse
-
#characterize(name, properties, type = Metadata) ⇒ Metadata
Creates a metadata instance for a subgroup of the metadata, such as a generated relation or for an optional parameter.
-
#initialize(name, properties = {}) ⇒ Metadata
constructor
A new instance of Metadata.
-
#relation_key ⇒ String
The key used to store the metadata inside the class’s ::relations attribute.
-
#relation_key? ⇒ Boolean
True if a custom relation key is defined, otherwise false.
Constructor Details
#initialize(name, properties = {}) ⇒ Metadata
Returns a new instance of Metadata.
16 17 18 19 20 21 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 16 def initialize name, properties = {} @name = name @properties = properties.dup merge! properties if Hash === properties end |
Instance Attribute Details
#name ⇒ Symbol (readonly)
Returns The name of the concern or relation.
24 25 26 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 24 def name @name end |
#properties ⇒ Hash (readonly)
Returns The unmodified properties hash that was passed into the constructor.
28 29 30 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 28 def properties @properties end |
Instance Method Details
#characterize(name, properties, type = Metadata) ⇒ Metadata
40 41 42 43 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 40 def characterize name, properties, type = nil type ||= Mongoid::SleepingKingStudios::Concern::Metadata type.new name, properties end |
#relation_key ⇒ String
The key used to store the metadata inside the class’s ::relations attribute. By default, adds the prefix ‘sleeping_king_studios::’ to the name, but can be set via the properties hash.
50 51 52 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 50 def relation_key self[:relation_key] || name.to_s end |
#relation_key? ⇒ Boolean
Returns True if a custom relation key is defined, otherwise false.
56 57 58 |
# File 'lib/mongoid/sleeping_king_studios/concern/metadata.rb', line 56 def relation_key? !!self[:relation_key] end |