Module: Mongoid::SleepingKingStudios::Concern
- Included in:
- HasTree, HasTree::CacheAncestry, Orderable, Sluggable
- Defined in:
- lib/mongoid/sleeping_king_studios/concern.rb,
lib/mongoid/sleeping_king_studios/concern/metadata.rb
Overview
Base class for concerns with shared behavior, such as creating metadata objects from an options hash and storing that metadata in the Document class’s ::relations attribute.
Defined Under Namespace
Classes: Metadata
Instance Method Summary collapse
-
#characterize(name, properties, type = Metadata) ⇒ Metadata
Creates a metadata instance for the relation.
-
#relate(base, name, metadata) ⇒ Object
Stores the metadata in the class’s relations object.
-
#valid_options ⇒ Array<Symbol>
Returns a list of options that are valid for this concern.
-
#validate_options(name, options) ⇒ Object
Evaluates the provided options and raises an error if any of the options are invalid, based on the list from #valid_options.
Instance Method Details
#characterize(name, properties, type = Metadata) ⇒ Metadata
22 23 24 25 |
# File 'lib/mongoid/sleeping_king_studios/concern.rb', line 22 def characterize name, , type = nil type ||= Mongoid::SleepingKingStudios::Concern::Metadata type.new name, end |
#relate(base, name, metadata) ⇒ Object
Stores the metadata in the class’s relations object. To avoid automatic Mongoid behavior on relations, adds a #sleeping_king_studios accessor to the relations hash by mixing in the Relations module. Then, saves the metadata using the metadata#relation_key as the key.
36 37 38 |
# File 'lib/mongoid/sleeping_king_studios/concern.rb', line 36 def relate base, name, base.relations_sleeping_king_studios.update .relation_key => end |
#valid_options ⇒ Array<Symbol>
Returns a list of options that are valid for this concern.
43 44 45 46 47 |
# File 'lib/mongoid/sleeping_king_studios/concern.rb', line 43 def %i( ) # end array end |
#validate_options(name, options) ⇒ Object
Evaluates the provided options and raises an error if any of the options are invalid, based on the list from #valid_options.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mongoid/sleeping_king_studios/concern.rb', line 57 def name, .keys.each do |key| if !.include?(key) raise Mongoid::Errors::InvalidOptions.new( name, key, ) # end InvalidOptions end # if end # each end |