class Mongoid::SleepingKingStudios::Concern::Metadata
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.
@since 0.6.0
Attributes
@return [Symbol] The name of the concern or relation.
@return [Hash] The unmodified properties hash that was passed into the
constructor.
Public Class Methods
@param [Symbol, String] name The name of the concern or relation. @param [Hash] properties The properties of the concern or relation.
# 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
Public Instance Methods
@overload characterize name, properties, type = Metadata
Creates a metadata instance for a subgroup of the metadata, such as a generated relation or for an optional parameter. @param [Symbol] name The name of the relation. Must be unique for the base type within the sleeping_king_studios namespace. @param [Hash] properties The options for the relation. @param [Class] type The type of the generated metadata. @return [Metadata] The generated metadata.
# 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
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.
@return [String] The key used to store the metadata.
# File lib/mongoid/sleeping_king_studios/concern/metadata.rb, line 50 def relation_key self[:relation_key] || name.to_s end
@return [Boolean] True if a custom relation key is defined, otherwise
false.
# File lib/mongoid/sleeping_king_studios/concern/metadata.rb, line 56 def relation_key? !!self[:relation_key] end