Class: StrokeDB::Document::Metas
Overview
Collection of meta documents
Constant Summary
Constants inherited
from Array
Array::SDATPTAGS
Instance Method Summary
collapse
Methods inherited from Array
#stroke_diff, #stroke_merge, #stroke_patch, #to_raw
Constructor Details
#initialize(document) ⇒ Metas
98
99
100
101
102
|
# File 'lib/strokedb/document.rb', line 98
def initialize(document)
@document = document
_meta = document[:meta]
concat _meta.to_a
end
|
Instance Method Details
104
105
106
|
# File 'lib/strokedb/document.rb', line 104
def <<(meta)
add_meta(meta, :call_initialization_callbacks => true)
end
|
108
|
# File 'lib/strokedb/document.rb', line 108
alias :_delete :delete
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/strokedb/document.rb', line 129
def add_meta(meta, opts = {})
opts = opts.stringify_keys
_module = nil
case meta
when Document
push meta
_module = StrokeDB::Document.collect_meta_modules(@document.store, meta).first
when Meta
push meta.document(@document.store)
_module = meta
else
raise ArgumentError, "Meta should be either document or meta module"
end
@document[:meta] = self
if _module
@document.extend(_module)
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
|
#delete(meta) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/strokedb/document.rb', line 109
def delete(meta)
case meta
when Document
_delete meta
_module = StrokeDB::Document.collect_meta_modules(@document.store, meta).first
when Meta
_delete meta.document(@document.store)
_module = meta
else
raise ArgumentError, "Meta should be either document or meta module"
end
@document[:meta] = self
if _module
@document.unextend(_module)
end
end
|