Class: StrokeDB::Document::Metas
- Defined in:
- lib/document/document.rb
Overview
Collection of meta documents
Constant Summary
Constants inherited from Array
Instance Method Summary collapse
- #<<(meta) ⇒ Object
- #add_meta(meta, opts = {}) ⇒ Object
-
#initialize(document) ⇒ Metas
constructor
:nodoc:.
Methods inherited from Array
#stroke_diff, #stroke_merge, #stroke_patch
Constructor Details
#initialize(document) ⇒ Metas
:nodoc:
82 83 84 85 86 |
# File 'lib/document/document.rb', line 82 def initialize(document) @document = document = document[:meta] concat [].flatten.compact.map{|v| v.is_a?(DocumentReferenceValue) ? v.load : v} end |
Instance Method Details
#<<(meta) ⇒ Object
88 89 90 |
# File 'lib/document/document.rb', line 88 def <<() (, :call_initialization_callbacks => true) end |
#add_meta(meta, opts = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/document/document.rb', line 92 def (, opts = {}) opts = opts.stringify_keys _module = nil # meta can be specified both as a meta document and as a module case when Document push _module = StrokeDB::Document.(@document.store, ).first when Meta push .document(@document.store) _module = else raise ArgumentError, "Meta should be either document or meta module" end # register meta in the document @document[:meta] = self if _module @document.extend(_module) _module.send!(:setup_callbacks, @document) rescue nil if opts['call_initialization_callbacks'] @document.send!(:execute_callbacks_for, _module, :on_initialization) @document.send!(:execute_callbacks_for, _module, :on_new_document) if @document.new? end end end |