Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Meta will automatically setup callbacks for a document when it extend…
…s it
  • Loading branch information
Yurii Rashkovskii committed May 4, 2008
1 parent 1b196b3 commit 96ea796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 0 additions & 3 deletions lib/strokedb/document.rb
Expand Up @@ -148,8 +148,6 @@ def add_meta(meta, opts = {})
if _module
@document.extend(_module)

_module.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?
Expand Down Expand Up @@ -341,7 +339,6 @@ def self.from_raw(store, raw_slots, opts = {}) #:nodoc:
collect_meta_modules(store, raw_slots['meta']).each do |meta_module|
unless doc.is_a? meta_module
doc.extend(meta_module)
meta_module.setup_callbacks(doc) rescue nil
end
end

Expand Down
9 changes: 8 additions & 1 deletion lib/strokedb/document/meta.rb
Expand Up @@ -252,6 +252,13 @@ def document(store=nil)
metadocs.size > 1 ? metadocs.inject { |a, b| a + b }.make_immutable! : metadocs.first
end

def extended(obj)
setup_callbacks(obj) if obj.is_a?(Document)
end


private

def make_document(store=nil)
raise NoDefaultStoreError.new unless store ||= StrokeDB.default_store
@meta_initialization_procs.each {|proc| proc.call }.clear
Expand Down Expand Up @@ -301,7 +308,7 @@ def add_callback(name,uid=nil, &block)
@callbacks ||= []
@callbacks << Callback.new(self, name, uid, &block)
end
public

def setup_callbacks(doc)
return unless @callbacks
@callbacks.each do |callback|
Expand Down

0 comments on commit 96ea796

Please sign in to comment.