<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -344,7 +344,6 @@ module StrokeDB
       collect_meta_modules(store, raw_slots['meta']).each do |meta_module|
         unless doc.is_a? meta_module
           doc.extend(meta_module)
-
           meta_module.send!(:setup_callbacks, doc) rescue nil
         end
       end
@@ -686,13 +685,21 @@ module StrokeDB
         if m = store.find($1, $2)
           mod = Module.find_by_nsurl(m[:nsurl])
           mod = nil if mod == Module
-          meta_names &lt;&lt; (mod ? mod.name : &quot;&quot;) + &quot;::&quot; + m[:name]
+          if (mod.nil? &amp;&amp; Object.constants.include?(m[:name])) || (mod &amp;&amp; mod.constants.include?(m[:name]))
+            meta_names &lt;&lt; (mod ? mod.name : &quot;&quot;) + &quot;::&quot; + m[:name]
+          else
+            meta_names &lt;&lt; Meta.resolve_uuid_name(m[:nsurl],m[:name])
+          end
         end
       when DOCREF
         if m = store.find($1)
           mod = Module.find_by_nsurl(m[:nsurl])
           mod = nil if mod == Module
-          meta_names &lt;&lt; (mod ? mod.name : &quot;&quot;) + &quot;::&quot; + m[:name]
+          if (mod.nil? &amp;&amp; Object.constants.include?(m[:name])) || (mod &amp;&amp; mod.constants.include?(m[:name]))
+            meta_names &lt;&lt; (mod ? mod.name : &quot;&quot;) + &quot;::&quot; + m[:name]
+          else
+            meta_names &lt;&lt; Meta.resolve_uuid_name(m[:nsurl],m[:name])
+          end
         end
       when Array
         meta_names = meta.map { |m| collect_meta_modules(store, m) }.flatten</diff>
      <filename>lib/strokedb/document.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,7 @@
 module StrokeDB
+  
+  META_CACHE = {}
+  
   # Meta is basically a type. Imagine the following document:
   #
   # some_apple:
@@ -20,8 +23,21 @@ module StrokeDB
   #
   # Document class will be extended by modules Fruit and Product.
   module Meta
-
+    
     class &lt;&lt; self
+
+      def resolve_uuid_name(nsurl,name)
+        &quot;meta:#{nsurl}##{name}&quot;
+      end
+
+      def make_uuid_from_fullname(full_name)
+        StrokeDB::Util.sha1_uuid(full_name)
+      end
+      
+      def make_uuid(nsurl, name)
+        StrokeDB::Util.sha1_uuid(&quot;meta:#{nsurl}##{name}&quot;)
+      end
+      
       def new(*args, &amp;block)
         mod = Module.new
         args = args.unshift(nil) if args.empty? || args.first.is_a?(Hash)
@@ -44,8 +60,13 @@ module StrokeDB
           initialize_coercions
           initialize_virtualizations
         end
-        if meta_name = extract_meta_name(*args)
-          Object.const_set(meta_name, mod)
+        if name = args.last.stringify_keys['name']
+          META_CACHE[make_uuid(args.last.stringify_keys['nsurl'],args.last.stringify_keys['name'])] = mod 
+          mod.instance_eval %{
+            def name 
+              '#{name}'
+            end
+          }
         end
         mod
       end
@@ -65,14 +86,6 @@ module StrokeDB
         @uuid ||= ::Util.sha1_uuid(&quot;meta:#{StrokeDB.nsurl}##{Meta.name.demodulize}&quot;)
       end
 
-      def extract_meta_name(*args)
-        if args.first.is_a?(Hash)
-          args.first[:name]
-        else
-          args[1][:name] unless args.empty?
-        end
-      end
-
     end
 
     def +(meta)
@@ -227,8 +240,6 @@ module StrokeDB
       metadocs.size &gt; 1 ? metadocs.inject { |a, b| a + b }.make_immutable! : metadocs.first
     end
     
-    private
-
     def make_document(store=nil)
       raise NoDefaultStoreError.new unless store ||= StrokeDB.default_store
       @meta_initialization_procs.each {|proc| proc.call }.clear
@@ -237,7 +248,7 @@ module StrokeDB
       values[:meta] = Meta.document(store)
       values[:name] ||= name.demodulize
       values[:nsurl] ||= name.modulize.empty? ? Module.nsurl : name.modulize.constantize.nsurl 
-      values[:uuid] ||= ::Util.sha1_uuid(&quot;meta:#{values[:nsurl]}##{values[:name]}&quot;) if values[:name]
+      values[:uuid] ||= Meta.make_uuid(values[:nsurl],values[:name]) if values[:name]
       
       if meta_doc = find_meta_doc(values, store)
         values[:version] = meta_doc.version</diff>
      <filename>lib/strokedb/document/meta.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,23 +13,6 @@ describe &quot;Meta meta&quot; do
 
 end
 
-describe &quot;Meta meta instantiation&quot; do
-
-  before(:each) do
-    # @store = mock(&quot;store&quot;)
-    # StrokeDB.stub!(:default_store).and_return(@store)
-    setup_default_store
-    Object.send!(:remove_const,'SomeName') if defined?(SomeName)
-    @meta = Meta.new(:name =&gt; &quot;SomeName&quot;)
-  end
-
-  it &quot;should create new meta module and bind it to name passed&quot; do
-    @meta.should be_a_kind_of(Meta)
-    SomeName.should == @meta
-  end
-
-end
-
 describe &quot;Meta meta instantiation with block specified&quot; do
   
   before(:each) do</diff>
      <filename>spec/lib/strokedb/document/meta_meta_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -32,7 +32,7 @@ describe &quot;Meta module&quot;, :shared =&gt; true do
     new_doc = nil
     2.times do |i|
       Object.send!(:remove_const,'SomeName') if defined?(SomeName)
-      @meta = Meta.new(:name =&gt; &quot;SomeName&quot;, :description =&gt; &quot;Something&quot;)  
+      SomeName = Meta.new(:description =&gt; &quot;Something&quot;)  
       new_doc = SomeName.document
     end
     new_doc.uuid.should == doc.uuid
@@ -162,6 +162,33 @@ describe &quot;Meta module without name&quot; do
   end
 end
 
+
+describe &quot;Meta module without constant definition&quot; do
+  
+  before(:each) do
+    setup_default_store
+    setup_index
+    @some_name = Meta.new(:name =&gt; 'SomeName') do
+      def some
+      end
+    end
+  end
+  
+  it &quot;should not set respective constant&quot; do
+    defined?(SomeName).should be_nil
+  end
+  
+  it &quot;should have its name constantizeable anyway&quot; do
+    Meta.resolve_uuid_name(&quot;&quot;,&quot;SomeName&quot;).constantize.should == @some_name
+  end
+
+  it &quot;should be loaded into document on its load&quot; do
+    doc = @some_name.create!.reload
+    doc.should respond_to(:some)
+  end
+
+end
+
 describe &quot;Meta module within no module&quot; do
   
   before(:each) do
@@ -254,7 +281,6 @@ describe &quot;Meta module with on_load callback&quot; do
   before(:each) do
     setup_default_store
     setup_index
-    
     Object.send!(:remove_const,'SomeName') if defined?(SomeName)
     SomeName = Meta.new do
       on_load do |obj|
@@ -271,7 +297,7 @@ describe &quot;Meta module with on_load callback&quot; do
   it &quot;should receive this callback on document load&quot; do
     doc = SomeName.create!
     Kernel.should_receive(:on_load_called).with(false)
-    SomeName.find(doc.uuid)
+    d = SomeName.find(doc.uuid)
   end
   
   </diff>
      <filename>spec/lib/strokedb/document/meta_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8156934c5d7220e480ddd05593024e970775cd8b</id>
    </parent>
    <parent>
      <id>591e7fe8a219f16de2f3428dc01950a67c231e90</id>
    </parent>
  </parents>
  <author>
    <name>Yurii Rashkovskii</name>
    <email>yrashk@gmail.com</email>
  </author>
  <url>http://github.com/yrashk/strokedb/commit/7baf51d0b769d745f286bb65eba72a99d263a7b7</url>
  <id>7baf51d0b769d745f286bb65eba72a99d263a7b7</id>
  <committed-date>2008-04-29T22:18:08-07:00</committed-date>
  <authored-date>2008-04-29T22:18:08-07:00</authored-date>
  <message>Merge branch 'master' into new-views</message>
  <tree>1361161ef75e493688daf46844fb26edfb9868fd</tree>
  <committer>
    <name>Yurii Rashkovskii</name>
    <email>yrashk@gmail.com</email>
  </committer>
</commit>
